Oxygen Basic

Programming => Example Code => Topic started by: Arnold on February 25, 2018, 04:46:15 AM

Title: Nehe tutorial in a dynamic dialog
Post by: Arnold on February 25, 2018, 04:46:15 AM
This is Nehe tutorial 8, modified a little bit and done using dynamic dialog templates. It should run in JIT mode, and run as a 32-bit and 64-bit exe. First there must be loaded an image, then start animation with Ctrl-P or Menuitem, then the keys can be used. F1 opens a Help Window, F11 toggles between FullScreen and normal windowed mode. All is developed using Oxygen and Winapi, no external libraries.

There are some issues. But as we expect some visits this afternoon, I can not address these problems until tomorrow.

Roland

Edit: I forgot about Ctrl-R. This will reset the Image to the original state. Replaced Tut08.o2bas with the adjusted Help Dialog

[attachment deleted by admin]
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on February 26, 2018, 12:37:45 AM
Hi Charles,

in order to use imgwin.inc for Nehe lesson 08 I had to use #case capital. I did not give much attention to this directive before but it is a powerful possibility to prevent ambiguities yet it also requires some discipline which I did not notice before.

Perhaps you could change in Dialogs.inc line 308 the naming of the sub to:
sub Control( string ....

Then there would be no need for: #def Control CONTROL in such cases. Exact naming would be required nevertheless, but this is ok.

The same problem occurs with OPENFILENAMEA in FileDialog.inc. If the types were written lowercase then there would be no need e.g.:
typedef sys SYS
typedef char CHAR
but I do not know if there was a special intention for using uppercase for this structure in FileDialog.inc

There is also an error message when using console.inc with #case capital:
ASM ERR: coord_op(..)!! Unidentified instruction: coord_op, line 131

If I comment out line 131:
'  dwConSize = csbi.dwSize.X * csbi.dwSize.Y;

I can use console.inc with Tut08.o2bas or other projects which add #case capital, but I assume there is an intention for this line? I do not understand why the COORD type is not recognized in this case.

With the latest release of OxygenBasic (Feb. 24) you changed something with using structures? Prior to this version I could use:

   ACCEL accl[13] = {
'   {asc("O"),      IDM_Load,       FVIRTKEY | FCONTROL},

Now I have to use:
    {79,      IDM_Load,             FVIRTKEY | FCONTROL},

Did this change happen intentionally?

Roland
 
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Charles Pegge on February 26, 2018, 08:43:34 AM
Hi Roland,

The capital X and Y in coord (console.inc) was causing problems for coordderived types

I have also found the asc("O") problem in the multiassign block, and will update oxygen.dll shortly.
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on February 27, 2018, 03:46:13 AM
Hi Charles,

may I ask you for some details about the structure of the program? I tried to code the subs similar to the original Nehe08.cpp, but using routines of glWinUtil, WinUtil and ImgWin. Now I am not sure if I did this correctly. My questions would be:
did I use glGentTextures / glDeleteTextures correctly?
Gdiplustoken, Gdiplus 0, Gdiplus 1: are there better ways to set these items?
SelectPixelFormat(hDlgHDC, 1) : This is only trial and error. Is this correct? What is the effect of 0, >0?
sub LoadGLTextures: This is also only experimenting. Would I need to load the image 3 times and use three wi[], ht[]?

Although I do not see a difference with the original program I wonder about the purpose of "Filter". I cannot see a different effect if I press 'F'.

Hopefully you will find some time to look at the code. I would like to use as much as possible of the Oxygenbasic library routines, though OpenglSceneFrame.inc is a bit too difficult for me at the moment.

Roland
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Charles Pegge on February 27, 2018, 12:54:18 PM
Hi Roland,

Your program looks pretty good to me, though I will have to walk through it to see if there are any problems managing textures etc. Would it be okay to add this to our example collection?

There is an example which may help demonstrate OpenglSceneFrame with popup menus:

examples/Opengl/MenuObj.o2bas

I use OSF with nearly all theOpengl demos. It is an aggregation  of many Nehe lessons, and performs well as base code, leaving you to deal with geometry, textures and animation. But I expect most developers will have their own fully customised 3d engines, honed to perfection.
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on February 28, 2018, 04:31:32 AM
Hi Charles,

thank you for pointing me to MenuObj.o2bas. It will take some time until I understand everything. I suppose it is too late for me to become an OpenGL expert, but I want to catch at least the basics.

Roland
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on March 31, 2018, 11:55:42 AM
Hi Charles,

I modified Nehe's lesson8 example a little bit for the latest OxygenBasicProgress installation and named it NeheTut08.o2bas. It can be run in JIT mode, and it can be compiled as a 32-bit or 64-bit executable. F1 for Help can always be called. I think the app is more user-friendly and it runs better in some cases e.g. changing to fullscreen / normal mode. Some activities are added e.g. Page up/down in reset mode.

I am still not sure if I used correctly glGenTextures in line 77 and glDeleteTextures in line 258. I am also insecure about sub LoadGLTextures, where I used 1 imgs instead of 3. IDM_FILTER in line 191 should change a filter, yet I do not see any effect with this feature. But I do not see an effect using the original program neither. Nethertheless I am quite happy with the app.

Quote
Would it be okay to add this to our example collection?

If there is / will be anything from me - unmodified or modified - which you consider to be usable, it will be an honor for me. I learned so much from you in the meantime, and if it is possible I would like to reciprocate.

Roland
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on March 31, 2018, 12:17:21 PM
Attached are the exe files for 32-bit and 64-bit

Edit: Deleted. Looking for a better solution.

Title: Re: Nehe tutorial in a dynamic dialog
Post by: chrisc on March 31, 2018, 01:11:37 PM
@Roland

My Mcafee AV detected the exe.zip file as virus "machine learning " !
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on March 31, 2018, 01:25:42 PM
Hi Chris,

I checked the files at www.virustotal.com before I uploaded them. These are the results:

NeheTut08_64.exe: 0 / 64
NeheTut08_32.exe: 3 / 66 - Avira, Bkav, Cylance
NeheTut08_exes.zip: 3 / 66 - Avira, Bkav, Cylance

McAfee did not give a warning. Is your version up-to-date?

Roland
Title: Re: Nehe tutorial in a dynamic dialog
Post by: chrisc on April 01, 2018, 08:10:47 AM
@Roland

never mind, the entire zip was capture and quarantin by Mcafee  AV.  but i was able to compile your o2bas file
and able to show the rotating images.  It is very good

Thanxx a lot


Title: Re: Nehe tutorial in a dynamic dialog
Post by: JRS on April 01, 2018, 09:58:49 AM
I highly recommend that members of the forum not upload .EXE files. Let the members of the forum compile the O2 source.
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on April 01, 2018, 11:11:57 AM
Maybe it is simpler to avoid uploading. But how will this help to minimize the problem of false postive notifications?
Title: Re: Nehe tutorial in a dynamic dialog
Post by: JRS on April 01, 2018, 12:50:47 PM
It seems like such a waste of Charles's time chasing down false positives. Maybe we need someone other than Charles to take on the task?





Title: Re: Nehe tutorial in a dynamic dialog
Post by: chrisc on April 01, 2018, 01:03:40 PM

Hello

i believe that the new AV uses Artificial Intelligence to check on unknown executables and their
behavior against their own benchmark,  if they found that the exe files behave differently and
it is unknown to them (not on their blacklists or white lists) they simply quarantine these files.
And let the user decides whether to erase them or not.

i find that AV now mainly capture unknown exe or dll mainly of the 32bit ones.

now i have to place in scan exclusions for Oxygen basic folders so that it won't capture any of my exe files
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Mike Lobanovsky on April 01, 2018, 02:47:26 PM
Maybe we need someone other than Charles to take on the task?

Not until O2 is finalized as a compiler. Then first, the compiler binaries should be made PE loader and AV heuristics compatible (icons, version info, manifests, checksums and stuff) and thus stable and recognizable binary-wise by their signatures.

And then, the executables that the compiler binaries would generate should undergo the same procedure so as to make the signatures the compiler leaves in them stable and known to the AV software.

We must live through this never ending stage of O2's WIP amorphousness, and see it come to an end before any serious work against false positives can be started. Otherwise we're going to simply waste our time and effort. Currently, O2 looks to the outside world as a polymorphic something that had better be avoided and quarantined just to be on the safe side.
Title: Re: Nehe tutorial in a dynamic dialog
Post by: JRS on April 01, 2018, 04:41:21 PM
I hate anti-virus software that assumes something is a risk and deletes it without giving the user the ability to override the decision.
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Aurel on April 01, 2018, 10:26:24 PM
chrisc

If your mcAfee detect something ... that mean that your computer is
already infected by malware.
I use Stringer and he detect trojan but cannot remove it.
So i use Kaspersky and clean computer without problem..
 every exe in oxygen folder was infected.
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on April 02, 2018, 04:48:51 PM
I downloaded the zip file of reply #7 and checked again with Virustotal. Then I did this also with my original files. As Virustotal also verifies some checksums I can be sure that the files are identical. This time the results are:

NeheTut08_64.exe: 0 / 66
NeheTut08_32.exe: 5 / 66 - Avira, Bkav, Cylance, Ikarus, Trendmicro-HouseCall
NeheTut08_exes.zip: 5 / 60 - Avira, Bkav, Cylance, Ikarus, Trendmicro-HouseCall

The number of vendors has changed a little bit and also the number of warnings, although I used the same files to examine. But this is no surprise as the vendors change their definition files daily. The results for 64-bit executables are better than for 32-bit exes. In the meantime I know that it makes no sense to get the executables whitelisted, because the next time I compile the same file anew I will get the same problem again.

Nevertheless I would like to provide some code and working examples. Is there a place where I could do this without creating an own website?

I will delete the zip file of reply #7 in the next two days.

Roland


Title: Re: Nehe tutorial in a dynamic dialog
Post by: JRS on April 02, 2018, 05:34:53 PM
You can upload the zips but also include a message what false positives may exist if you feel it's necessary. The members of the forum trust you.

I would like to agree on an online scanner results and post a link to the results.

I'm taking Mike's advice and not worrying about false positives until proper signing is part of the compiling process.

If someone is worried about the precompiled example, let them compile it from source.
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Mike Lobanovsky on April 02, 2018, 07:18:24 PM
In the meantime, we could try and introduce the following convention to allow for executable files in our attachments on this site:Note that this measure may still require that the files in the archive be explicitly unblocked upon downloading from the net. Once downloaded and extracted from the archive, rename the files back to their original extensions following the convention as per Item 1 above.

NOTE: The LZMA compression/decompression algorithm (a.k.a. deflate/inflate) is in the Public Domain (https://www.7-zip.org/sdk.html), which means unrestricted use for any puspose. LZMA is 7-zip's main algorithm to archive binary executable code. :)
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on April 03, 2018, 01:06:21 AM
Hi Mike,

I tried the procedure of renaming the files too, but these special AV-Scanners are clever enough to recognize the type of a file. But to compress the files to .7z is a good idea, it will reduce the size of the files still more.

The reason why I do not want to operate my own website are the regulations in my country for the legal notice. Although it would be only a private site, I could be required to make public my private address and telephone number to avoid litigation. And since I do not do anything commercial this is not worth the effort.

Roland
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Mike Lobanovsky on April 03, 2018, 03:22:59 AM
Ah yes!

"In the meantime" since I visited virustotal last (which was probably a year ago), Avira, Ikarus and TrendMicro-HouseCall  have been "clever" enough to add .7z and linuxoid .X (a.k.a. LZMA) archive file formats to their engines (or they may as well use common "malware signatures database" thus parasitizing on one another) to be able to inflate them and check the insides literally against possible PE file header content. ;)

Well, we could write our own custom compressor that would use neither 7-zip nor LZMA signatures ("fourcc" codes) directly yet remain as efficient at compressing its archived content. Then virustotal would have no hints left at their disposal to guess it's dealing with an archive rather than some meaningless binary stream. ;D

Should we, do you think? :)
Title: Re: Nehe tutorial in a dynamic dialog
Post by: jcfuller on April 03, 2018, 04:07:59 AM
Mike,
  I've used this for years for my own internal work.
http://ibsensoftware.com/products_aPLib.html
James
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Mike Lobanovsky on April 03, 2018, 06:12:33 AM
James,

Thanks for pointing this one out; it's cool. :)

However, LZMA goes significantly deeper than pure LZ. So, if we're talking in terms of static archive compression rather than Windows PE executable packing and decompression on the fly (similar to UPX), and (de)compression speed and memory footprint aren't too much of a concern, then on the average, general-purpose LZMA/LZMA2 would probably be better suited for the task than anything else these days.
Title: Re: Nehe tutorial in a dynamic dialog
Post by: chrisc on April 03, 2018, 06:50:10 AM
Hello all

i think we should include a version info into any dll and exe that we produce, doing this way will
at least inform AVs that the executables are not unknowns.   AVs are always on the look out for
unknown executables and then check their behavior against their benchmark of known malwares
characteristics and signatures. 

 when i was using PB,  my AV would sometimes quarantin those executables
without version info.  but once i placed in the version info,  the AV would stop capturing them.
So for O2, i will place in the version info for most of the executables.

some thing like this

Code: [Select]
1 VERSIONINFO
FILEVERSION 1, 0, 0, 0
PRODUCTVERSION 1, 0, 0, 0
FILEOS 0x00000004     // WINDOWS32
FILETYPE 0x00000001   // APP
BEGIN
  BLOCK "StringFileInfo"
  BEGIN
    BLOCK "040904E4"
    BEGIN
      VALUE "CompanyName",      "Your company\0"
      VALUE "FileDescription",  "myApp\0"
      VALUE "FileVersion",      "1.0.0.0\0"
      VALUE "InternalName",     "myApp\0"
      VALUE "OriginalFilename", "myApp.exe\0"
      VALUE "LegalCopyright",   "Copyright(c) 2018 Your company\0"
      VALUE "ProductName",      "myApp\0"
      VALUE "ProductVersion",   "1.0.0.0\0"
    END
  END
  BLOCK "VarFileInfo"
  BEGIN
    VALUE "Translation", 0x409, 0x04E4
  END
END 

1 MANIFEST "win10theme.xml"
Title: Re: Nehe tutorial in a dynamic dialog
Post by: chrisc on April 03, 2018, 07:50:34 AM
By the way, i found that my version info (in the above post) has a line

Code: [Select]
FILEOS 0x00000004     // WINDOWS32

as this pertains to 32bit windows how to to change this to windows 64?

can someone help me on this? Thanxx and appreciate your help
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on April 03, 2018, 08:30:35 AM
Hi Chris,

in my winver.h include file I found these definitions:

#define VOS_UNKNOWN  0x00000000
#define VOS_DOS  0x00010000
#define VOS_OS216  0x00020000
#define VOS_OS232  0x00030000
#define VOS_NT  0x00040000
#define VOS_WINCE  0x00050000L

#define VOS__BASE  0x00000000
#define VOS__WINDOWS16  0x00000001
#define VOS__PM16  0x00000002
#define VOS__PM32  0x00000003
#define VOS__WINDOWS32  0x00000004

#define VOS_DOS_WINDOWS16  0x00010001
#define VOS_DOS_WINDOWS32  0x00010004
#define VOS_OS216_PM16  0x00020002
#define VOS_OS232_PM32  0x00030003
#define VOS_NT_WINDOWS32  0x00040004

So I am not sure if there is a special value for win64. The value 0x04 should be sufficient. See also this VERSIONFINFO Resource example:


https://thronic.com/Notes/C/Win32-VERSIONINFO/
 (https://thronic.com/Notes/C/Win32-VERSIONINFO/)

The values for VFT_ are defined as:

#define VFT_UNKNOWN  0
#define VFT_APP  1
#define VFT_DLL  2
#define VFT_DRV  3
#define VFT_FONT  4
#define VFT_VXD  5
#define VFT_STATIC_LIB  7

Roland
Title: Re: Nehe tutorial in a dynamic dialog
Post by: chrisc on April 03, 2018, 10:11:11 AM
Thanxx Roland

i think i'll keep the version info as it is since it doesn't have any bearing with the executables
as when included into the compile assembly for 64bit,  the executables are functioning in 64bits
as  reviewed by the Task Manager.  So lets' keep it as it is
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on April 18, 2018, 02:09:33 AM
This is NeHe tutorial 10 using a dialog as main window, a little bit modified. It can be run in JIT mode, compiled to 32-bit or 64-bit executable. F1 will open the Help Message. Some nice effects are possible.

Roland
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on April 19, 2018, 08:09:28 AM
I could not resist and tried some of Peter's images. There are some very nice results possible.
Title: Re: Nehe tutorial in a dynamic dialog
Post by: Arnold on May 03, 2018, 03:18:18 AM
Hello,

this is Nehe tutorial lesson 11, adapted for Oxygenbasic. As an exercise I used MainWindow (winutil.inc) as main. I think the app works quite nice.

Roland

Code: OxygenBasic
  1. 'http://nehe.gamedev.net/tutorial/flag_effect_(waving_texture)/16002/
  2. 'Adapted from Nehe tutorial lesson 11, uses MainWindow (winutil.inc)
  3. 'F1 opens Help
  4.  
  5. $ filename "NeheTut11.exe"
  6. 'uses RTL32
  7. 'uses RTL64
  8.  
  9. sys hAccel
  10. sys HelpDlg
  11.  
  12. macro InMessageLoop
  13.    if TranslateAccelerator( hWnd, hAccel, @wm ) = 0 then    
  14.      if not IsDialogMessage(hWnd, &wm) then
  15.        if IsDialogMessage( HelpDlg,  &wm ) = 0 then
  16.          TranslateMessage(&wm)
  17.          DispatchMessage(&wm)
  18.        end if  
  19.      end if
  20.    end if
  21. end macro
  22.  
  23. % FileDialogs       'opens FileDialog in winutil.inc
  24.  
  25. #case capital
  26. typedef sys SYS     'FileDialog.inc
  27. typedef char CHAR   'FileDialog.inc
  28.  
  29. uses winutil
  30. uses glWinUtil
  31. uses imgwin
  32.  
  33. '% review
  34. uses dialogs
  35. #autodim off
  36.  
  37. indexbase 0
  38.  
  39. % DS_CENTER=0x0800
  40. % SM_CYCAPTION 4
  41. % SWP_NOSIZE 0X1
  42. % SWP_NOZORDER 0X4
  43.  
  44. #define IDM_Load  1001
  45. #define IDM_Exit  1002
  46. #define IDM_Play  1003
  47. #define IDM_Reset 1004
  48. #define IDM_Help  1005
  49.  
  50. 'Ids for text controls in Help
  51. % IDC_LText1=1131
  52. % IDC_LText2=1132
  53.  
  54. /*
  55. declare sub InitGL()
  56. declare function initMenu(sys hWnd) as sys
  57. declare sub LoadGLTextures()
  58. declare sub DrawGLScene ()
  59. declare sub ReSizeGLScene (GLsizei width, GLsizei height)
  60. declare function GetTheFileName(string name, int a, optional string myfilter="", mytitle="") as string
  61. */
  62. #lookahead
  63.  
  64.  
  65. float points[45*45*3]    ' The Array For The Points On The Grid Of Our "Wave"
  66. macro points3d float* (r,x1,y1,z1)
  67.   'r return value
  68.  @r=@points( (x1)*45*3 + (y1)*3 + (z1) )
  69. end macro
  70.  
  71. int wiggle_count = 0     ' Counter Used To Control How Fast Flag Waves
  72.  
  73. GLfloat    xrot          'X Rotation
  74. GLfloat    yrot          'Y Rotation
  75. GLfloat    zrot          'Z Rotation
  76. GLfloat hold             'Temporarily Holds A Floating Point Value
  77.  
  78. static bool p_toggle   'Play ON/OFF
  79.  
  80. sys GdiplusToken
  81. GLuint texture[1]      'Storage for one Texture
  82. GLuint wi[1],ht[1]
  83.  
  84. 'Prepare Textures
  85. '----------------
  86. glGenTextures 1, texture
  87.  
  88.  
  89. bool is_loaded
  90. macro refreshScene()
  91.   if is_loaded then DrawGlScene()
  92.   SwapBuffers(hWndHDC)
  93. end macro
  94.  
  95. string fn=""
  96.  
  97. sys hWndHDC
  98. sys hMenu
  99. sys hInstance=inst
  100.  
  101. MainWindow(640,480,WS_OVERLAPPEDWINDOW, 2)
  102.  
  103. function WndProc ( hWnd, wMsg, wParam, lParam ) as sys callback
  104.  
  105.   select wMsg
  106.     case WM_CREATE
  107.     hMenu = initMenu(hWnd)
  108.     if SetMenu( hWnd, hMenu ) = 0 then
  109.       mbox "SetMenu hMenu failed!"
  110.     end if
  111.  
  112.     sys hGLrc
  113.     hWndhDC = GetDC( hWnd )
  114.  
  115.     SetWindowText(hWnd, "Nehe Lesson 11")
  116.  
  117.     'glWinUtil.inc
  118.    SelectPixelFormat(hWndHDC, 1)
  119.  
  120.     hGLrc = wglCreateContext( hWndHDC )
  121.     if hGLrc = 0 then
  122.       MessageBox( hWnd, "wglCreateContext failed", 0, 0 )
  123.       DestroyWindow( hWnd )
  124.     end if
  125.  
  126.     if wglMakeCurrent( hWndHDC, hGLrc ) = 0 then
  127.       MessageBox( hWnd, "wglMakeCurrent failed", 0, 0 )
  128.       DestroyWindow( hWnd )
  129.     end if
  130.  
  131.     InitGL()
  132.  
  133.     case WM_COMMAND
  134.       select loword(wParam)
  135.       case IDM_Exit      
  136.          SendMessage hWnd, WM_CLOSE, 0, 0
  137.  
  138.       case IDCANCEL
  139.          SendMessage hWnd, WM_CLOSE, 0, 0
  140.          
  141.       case IDM_Load
  142.          fn=GetTheFileName("", 0, "", "Please select Image to load")
  143.          if fn then
  144.            is_loaded=true
  145.            LoadGLTextures()
  146.            refreshScene
  147.          end if
  148.  
  149.       case IDM_Play
  150.          p_toggle = not p_toggle
  151.          
  152.       case IDM_Reset
  153.          xrot=0.0f
  154.          yrot=0.0f
  155.          zrot=0.0f
  156.  
  157.       case IDM_Help
  158.         'Open Help Window if not already open
  159.        if IsWindow( HelpDlg ) = 0 then
  160.           sys lpdt    
  161.           dyn::init(lpdt)
  162.  
  163.           Dialog( 2,  0, 0, 150, 100, "Buttons used:", lpdt,
  164.                  WS_OVERLAPPED or WS_SYSMENU or DS_CENTER or WS_VISIBLE or DS_SETFONT,
  165.                  10, "MS Sans Serif" )
  166.  
  167.           LTEXT( "", IDC_LText1,  5, 5, 50, 120 )
  168.           LTEXT( "", IDC_LText2, 55, 5,110, 120 )
  169.  
  170.           HelpDlg = CreateModelessDialog( hWnd, @HelpDlgProc, 0, lpdt )
  171.         end if
  172.  
  173.       end select
  174.        
  175.     case WM_PAINT
  176.        refreshScene
  177.  
  178.     case WM_SIZE    
  179.        ReSizeGLScene(loword(lParam),hiword(lParam)) ' LoWord=Width, HiWord=Height
  180.       refreshScene
  181.  
  182.     case WM_ERASEBKGND
  183.        return 0
  184.  
  185.     case WM_CLOSE
  186.        DestroyWindow(hWnd)
  187.  
  188.     case WM_DESTROY
  189.        glDeleteTextures 1, texture
  190.        Gdiplus 0
  191.  
  192.        if hGLrc then                                 'Rendering Context?
  193.         if not wglMakeCurrent(null,null) then       'Release the DC And RC Contexts
  194.           MessageBox(null,"Release Of DC And RC Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION)
  195.          end if
  196.          if not wglDeleteContext(hGLrc) then         'Delete the RC
  197.           MessageBox(null,"Release Rendering Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION)
  198.          end if
  199.          hGLrc=null                                  'Set RC to null
  200.       end if
  201.  
  202.        if hWndHDC then
  203.          if not ReleaseDC(hWnd,hWndHDC) then         'Release The DC
  204.           MessageBox(null,"Release Device Context Failed.","SHUTDOWN ERROR",MB_OK | MB_ICONINFORMATION)
  205.            hWndHDC=null                              'Set DC to null
  206.         end if
  207.        end if                
  208.        PostQuitMessage 0
  209.  
  210.     case else          
  211.        return DefWindowProc hWnd,wMsg,wParam,lParam
  212.  
  213.     end select
  214.  
  215. end function ' WndProc
  216.  
  217.  
  218. '====================================================================
  219.  
  220. function initMenu(sys hWnd) as sys
  221.  
  222.    indexbase 1
  223.  
  224.    MENU(hMenu)
  225.  
  226.    BEGIN
  227.      POPUP "&File"
  228.      BEGIN
  229.        MENUITEM "&Load Image..." tab "Ctrl+O", IDM_Load
  230.        MENUITEM "SEPARATOR"
  231.        MENUITEM "E&xit" tab "Alt+F4", IDM_Exit
  232.      ENDMenu
  233.      POPUP "&View"
  234.      BEGIN
  235.        MENUITEM "&Toggle Start / Stop" tab "Ctrl+P", IDM_Play
  236.        MENUITEM "SEPARATOR"
  237.        MENUITEM "&Reset" tab "Ctrl+R", IDM_Reset
  238.      ENDMenu
  239.      POPUP "&Help"
  240.      BEGIN
  241.        MENUITEM "&Key Options" tab "F1", IDM_Help
  242.      ENDMenu
  243.    ENDMenu
  244.  
  245.    'Accelerators
  246.   indexbase 0
  247.    ACCEL accl[3] = {
  248.    {FVIRTKEY | FCONTROL, asc("O"), IDM_Load      },
  249.    {FVIRTKEY | FCONTROL, asc("P"), IDM_Play     },
  250.    {FVIRTKEY | FCONTROL, asc("R"), IDM_Reset     },
  251.    {FVIRTKEY,            VK_F1,    IDM_Help      }
  252.    }
  253.  
  254.    hAccel = CreateAcceleratorTable( @accl, 4 )
  255.  
  256.    return hMenu
  257. end function
  258.  
  259. sub LoadGLTextures()  ' Load Bitmaps And Convert To Textures
  260.   static sys res
  261.    string imgs[1]=""
  262.    'load an image file directly as a new OpenGL texture
  263.   LoadPixImage fn,res,imgs[1],wi[1],ht[1]
  264.  
  265.    'Typical Texture Generation Using Data From The Bitmap
  266.   glBindTexture(GL_TEXTURE_2D, texture[1])
  267.    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR)
  268.    glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR)
  269.    glTexImage2D GL_TEXTURE_2D, 0, 4, wi[1], ht[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, strptr imgs[1]
  270. end sub
  271.  
  272. sub InitGL()
  273.    GDIplus 1
  274.  
  275.    'SYNC FRAME RATE - 60HZ
  276.   sys p=wglgetprocaddress "wglSwapIntervalEXT" : call p 1
  277.  
  278.    glEnable(GL_TEXTURE_2D)                            'Enable Texture Mapping
  279.                                                      'All Setup For OpenGL Goes Here
  280.   glShadeModel(GL_SMOOTH)                            'Enable Smooth Shading
  281.   glClearColor(0.0f, 0.0f, 0.0f, 0.5f)               'Black Background
  282.   glClearDepth(1.0f)                                 'Depth Buffer Setup
  283.   glEnable(GL_DEPTH_TEST)                            'Enables Depth Testing
  284.   glDepthFunc(GL_LEQUAL)                             'The Type Of Depth Testing To Do
  285.   glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST)  'Really Nice Perspective Calculations
  286.   glPolygonMode( GL_BACK, GL_FILL )                  ' Back Face Is Solid
  287.   glPolygonMode( GL_FRONT, GL_LINE )                 ' Front Face Is Made Of Lines
  288.  
  289.    ' Loop Through The X Plane
  290.   int x,y
  291.    float xf,yf
  292.    for x=0 to <45
  293.       xf=float(x)
  294.       for y=0 to <45
  295.          yf=float(y)
  296.          points3d(x,y,0)= (xf/5.0f)-4.5f
  297.          points3d(x,y,1)= (yf/5.0f)-4.5f
  298.          points3d(x,y,2)= sin((((xf/5.0f)*40.0f)/360.0f)*3.141592654*2.0f)
  299.       next y
  300.    next x
  301.  
  302. end sub
  303.  
  304. sub DrawGLScene ()
  305.    int x, y
  306.    float xf,yf
  307.    float float_x, float_y, float_xb, float_yb
  308.  
  309.    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)   ' Clear The Screen And The Depth Buffer
  310.   glLoadIdentity()                                     ' Reset The View
  311.  
  312.    glTranslatef(0.0f,0.0f,-12.0f)
  313.      
  314.    glRotatef(xrot,1.0f,0.0f,0.0f)
  315.    glRotatef(yrot,0.0f,1.0f,0.0f)  
  316.    glRotatef(zrot,0.0f,0.0f,1.0f)
  317.  
  318.    glBindTexture(GL_TEXTURE_2D, texture[0])
  319.  
  320.    glBegin(GL_QUADS)
  321.    for x = 0 to <44
  322.        xf=float(x)
  323.       for y = 0 to <44
  324.          yf=float(y)
  325.          float_x = xf/44.0f
  326.          float_y = yf/44.0f
  327.          float_xb = (xf+1)/44.0f
  328.          float_yb = (yf+1)/44.0f
  329.  
  330.          glTexCoord2f( float_x, float_y)
  331.          glVertex3f( points3d(x,y,0), points3d(x,y,1), points3d(x,y,2) )
  332.  
  333.          glTexCoord2f( float_x, float_yb )
  334.          glVertex3f( points3d(x,y+1,0), points3d(x,y+1,1), points3d(x,y+1,2) )
  335.  
  336.          glTexCoord2f( float_xb, float_yb )
  337.          glVertex3f( points3d(x+1,y+1,0), points3d(x+1,y+1,1), points3d(x+1,y+1,2) )
  338.  
  339.          glTexCoord2f( float_xb, float_y )
  340.          glVertex3f( points3d(x+1,y,0), points3d(x+1,y,1), points3d(x+1,y,2) )
  341.       next y
  342.    next x
  343.    glEnd()
  344.  
  345.    if wiggle_count = 2 then
  346.       for y = 0 to <45
  347.          hold=points3d(0,y,2)
  348.          for x = 0 to <44
  349.             points3d(x,y,2) = points3d(x+1,y,2)
  350.          next x
  351.          points3d(44,y,2)=hold
  352.       next y
  353.       wiggle_count = 0
  354.    end if
  355.  
  356.    if p_toggle then
  357.      wiggle_count++
  358.    
  359.      xrot+=0.3f
  360.      yrot+=0.2f
  361.      zrot+=0.4f
  362.    end if    
  363. end sub
  364.  
  365. sub ReSizeGLScene (GLsizei width, GLsizei height)  ' Resize And Initialize The GL Window
  366.   if height=0 then              ' Prevent A Divide By Zero By
  367.     height=1                    ' Making Height Equal One
  368.   end if
  369.  
  370.    glViewport(0,0,width,height)  ' Reset The Current Viewport
  371.  
  372.    glMatrixMode(GL_PROJECTION)   ' Select The Projection Matrix
  373.   glLoadIdentity()              ' Reset The Projection Matrix
  374.  
  375.    ' Calculate The Aspect Ratio Of The Window
  376.   gluPerspective(45.0f, width/ height,0.1f,100.0f)
  377.  
  378.    glMatrixMode(GL_MODELVIEW)    ' Select The Modelview Matrix
  379.   glLoadIdentity()              ' Reset The Modelview Matrix
  380. end sub
  381.  
  382. function GetTheFileName(string name, int a, optional string myfilter="", mytitle="") as string
  383.    'adapted from FileDialog.inc
  384.   sys hwnd
  385.    char fdir[512] : GetCurrentDirectory 512, fdir
  386.    string dir = fdir
  387.  
  388.    string sep=chr(0)
  389.    string filter=
  390.      "images"+sep+"*.bmp;*.jpg;*.jpeg;*.png;*.tif;*.tiff;*.gif;*.ico"+sep+
  391.      "all files"+sep+"*.*"+sep+sep
  392.    if len(myfilter) then filter=myfilter + sep
  393.  
  394.    string title
  395.    if a then
  396.      title="Save File as"
  397.    else
  398.      title="Load File"
  399.    end if
  400.    if len mytitle then title=mytitle
  401.  
  402.    sys flags = OFN_EXPLORER or OFN_PATHMUSTEXIST or OFN_FILEMUSTEXIST or OFN_OVERWRITEPROMPT or OFN_HIDEREADONLY
  403.    string fname = FileDialog(dir,filter,title,name,hwnd,flags,a)
  404.  
  405.    return fname
  406. end function
  407.  
  408. function HelpDlgProc( sys hDlg, uint uMsg, sys wParam, lParam) as sys callback
  409.    string Result
  410.    sys hLText1=GetDlgItem(hDlg, IDC_LText1)
  411.    sys hLText2=GetDlgItem(hDlg, IDC_LText2)
  412.  
  413.    select case uMsg
  414.  
  415.      case WM_INITDIALOG
  416.         string HelpText1 =
  417. "
  418. F1          
  419. Ctrl-O
  420. Ctrl-P
  421. Ctrl-R
  422. ESC
  423. Alt-F4  
  424. "
  425.         string HelpText2 =
  426. "      
  427. This Help  
  428. Load an image      
  429. Start / Stop Animation
  430. Reset to original state    
  431. Quit
  432. Quit
  433. "
  434.         SetWindowText (hLText1, HelpText1)
  435.         SetWindowText (hLText2, HelpText2)      
  436.        
  437.      case WM_COMMAND
  438.         select case loword(wParam)      
  439.           case IDCANCEL
  440.              DestroyWindow( hDlg )
  441.         end select
  442.  
  443.      case WM_CLOSE
  444.         DestroyWindow( hDlg )
  445.  
  446.         'Reset Help dialog
  447.        HelpDlg = 0
  448.  
  449.    end select
  450.  
  451.    return 0
  452. end function
  453.