Author Topic: FreeGlut  (Read 6701 times)

0 Members and 1 Guest are viewing this topic.

Charles Pegge

  • Guest
FreeGlut
« on: June 08, 2012, 02:29:26 PM »

Code: OxygenBasic
  1.  
  2.  
  3. 'http://www.opengl.org/archives/resources/code/samples/glut_examples/examples/examples.html
  4.  
  5. include "freeglut.inc"
  6. indexbase   0
  7.  
  8.  
  9. 'CUBE
  10.  
  11. /* Copyright (c) Mark J. Kilgard, 1997. */
  12.  
  13. /* This program is freely distributable without licensing fees
  14.    and is provided without guarantee or warrantee expressed or
  15.    implied. This program is -not- in the public domain. */
  16.  
  17. /* This program was requested by Patrick Earl; hopefully someone else
  18.    will write the equivalent Direct3D immediate mode program. */
  19.  
  20.  
  21. GLfloat light_diffuse[4] = {1.0, 0.0, 0.0, 1.0}  'Red diffuse light.
  22.  
  23. GLfloat light_position[4] = {1.0, 1.0, 1.0, 0.0}  'Infinite light location.
  24.  
  25. 'arrays- major minor
  26.  
  27. 'Normals for the 6 faces of a cube.
  28. 'float n[6][3]
  29. GLfloat n[18]
  30. n=>
  31. -1.0, 0.0, 0.0, 'left
  32. 0.0, 1.0, 0.0, 'top
  33. 1.0, 0.0, 0.0, 'right
  34. 0.0,-1.0, 0.0, 'bottom
  35. 0.0, 0.0, 1.0, 'front
  36. 0.0, 0.0,-1.0  'back
  37.  
  38. 'Vertex indices for the 6 faces of a cube.
  39. 'int faces[6][4]
  40. GLint faces[24]
  41. faces=>
  42.  0, 1, 2, 3,
  43.  3, 2, 6, 7,
  44.  7, 6, 5, 4,
  45.  4, 5, 1, 0,
  46.  5, 6, 2, 1,
  47.  7, 4, 0, 3
  48.  
  49. 'Will be filled in with X,Y,Z vertexes.
  50. 'float v[8][3]
  51. GLfloat v[24]
  52.  
  53.  
  54. sub drawBox
  55.   sys i
  56.   for i=0 to <6
  57.     glBegin(GL_QUADS)
  58.     glNormal3fv n[i*3]
  59.     glVertex3fv v[faces[i*4  ]*3]
  60.     glVertex3fv v[faces[i*4+1]*3]
  61.     glVertex3fv v[faces[i*4+2]*3]
  62.     glVertex3fv v[faces[i*4+3]*3]
  63.     glEnd();
  64.   next
  65. end sub
  66.  
  67. sub display() callback
  68.   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
  69.   drawBox()
  70.   glutSwapBuffers()
  71. end sub
  72.  
  73.  
  74. sub init
  75.   '
  76.  'Setup cube vertex data.
  77.  'x
  78.  v[0]=-1 : v[3]=-1 : v[6]=-1 : v[9]=-1
  79.   v[12]=1 : v[15]=1 : v[18]=1 : v[21]=1
  80.   'y
  81.  v[1]=-1 : v[4]=-1 : v[13]=-1 : v[16]=-1
  82.   v[7]=1  : v[10]=1 : v[19]=1  : v[22]=1
  83.   'z
  84.  v[2]=1  : v[11]=1 : v[14]=1  : v[23]=1
  85.   v[5]=-1 : v[8]=-1 : v[17]=-1 : v[20]=-1
  86.   '
  87.  'Enable a single OpenGL light.
  88.  '
  89.  glLightfv GL_LIGHT0, GL_DIFFUSE, light_diffuse
  90.   glLightfv GL_LIGHT0, GL_POSITION, light_position
  91.   glEnable GL_LIGHT0
  92.   glEnable GL_LIGHTING
  93.   '
  94.  'Use depth buffering for hidden surface elimination.
  95.  '
  96.  glEnable GL_DEPTH_TEST
  97.  
  98.   'Setup the view of the cube.
  99.  
  100.   glMatrixMode GL_PROJECTION
  101.   gluPerspective 40.0, 1.0, 1.0, 10.0
  102.   glMatrixMode GL_MODELVIEW
  103.   '
  104.  '         eye pos,        center pos      up vector
  105.  '
  106.  gluLookAt 0.0, 0.0, 5.0,  0.0, 0.0, 0.0,  0.0, 1.0, 0.0
  107.  
  108.   'Adjust cube position to be asthetic angle.
  109.  
  110.   glTranslatef       0.0,  0.0, -1.0
  111.   glRotatef     60,  1.0,  0.0,  0.0
  112.   glRotatef    -20,  0.0,  0.0,  1.0
  113.   '
  114. end sub
  115.  
  116.  
  117.  
  118. function main(int argc, char **argv) as sys
  119.   glutInit argc, argv
  120.   glutInitDisplayMode GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH
  121.   glutCreateWindow "red 3D lighted cube"
  122.   glutDisplayFunc @display 'set csllback
  123.  init
  124.   glutMainLoop
  125.  return 0             /* ANSI C requires main to return int. */
  126. end function
  127.  
  128. main null,null
  129.  

To run, place the glut folder in the projects folder (it needs the GL headers)

Charles

Peter

  • Guest
Re: FreeGlut
« Reply #1 on: June 08, 2012, 02:47:46 PM »
cool Charles!

Try this Triangle!
Code: [Select]
Include "gl3d.inc"

Screen 1024,768,3
SetCaption "PYRAMID"
'Finit

single r, sys kris
Kris = LoadTexture "gfx/kristal256.gfx",256,256

While Key(27)=0
glClearColor  0.0, 0.2, 0.5, 1.0
glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT

glLoadIdentity
glBindTexture GL_TEXTURE_2D, Texture(kris)
glTranslatef -0.0, -0.1, 0.0
glRotatef r, 0.0, 1.0, 0.0 

glBegin GL_TRIANGLES    
  glTexCoord2f 1.0, 0.0: glVertex3f( 0.0, 0.5, 0.0)
  glTexCoord2f 1.0, 1.0: glVertex3f(-0.5,-0.5, 0.5)
  glTexCoord2f 0.0, 1.0: glVertex3f( 0.5,-0.5, 0.5)
  glTexCoord2f 0.0, 0.0: glVertex3f( 0.0, 0.5, 0.0)
 
  glTexCoord2f 1.0, 0.0: glVertex3f( 0.5,-0.5, 0.5)
  glTexCoord2f 1.0, 1.0: glVertex3f( 0.5,-0.5,-0.5)
  glTexCoord2f 0.0, 1.0: glVertex3f( 0.0, 0.5, 0.0)
  glTexCoord2f 0.0, 0.0: glVertex3f( 0.5,-0.5,-0.5)
 
  glTexCoord2f 1.0, 0.0: glVertex3f(-0.5,-0.5,-0.5)
  glTexCoord2f 1.0, 1.0: glVertex3f( 0.0, 0.5, 0.0)
  glTexCoord2f 0.0, 1.0 :glVertex3f(-0.5,-0.5,-0.5)
  glTexCoord2f 0.0, 0.0 :glVertex3f(-0.5,-0.5, 0.5)
glEnd

 r +=1
 
DoEvents
SwapBuffers hdc
SetFps 90
Wend
WinEnd

Peter

  • Guest
Re: FreeGlut
« Reply #2 on: June 08, 2012, 02:56:26 PM »
And this Cube.
Code: [Select]
include "GL3D.inc"

Screen 1024,768,0
Finit

Long a, b, face, holz
face= LoadTexture "gfx/face512.gfx",512,512
holz= LoadTexture "gfx/holz64.gfx",64,64

single r4X,r4Y,r4Z

While WinExit=0
iF Key(vk_escape) Then WinExit=1
glClearColor 0.5, 0.2, 0.8, 1.0
glClear GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT       
glLoadIdentity

glTranslatef 0.0, 0.0, 0.0
glRotatef r4X, 1.0, 0.0, 0.0
glRotatef r4Y, 0.0, 1.0, 0.0
glRotatef r4Z, 0.0, 0.0, 1.0

glBindTexture GL_TEXTURE_2D, Texture(face)
glBegin GL_QUADS
 glTexCoord2f 1.0, 1.0: glVertex3f (  0.1 , 0.1 ,- 0.1 )
 glTexCoord2f 0.0, 1.0: glVertex3f (- 0.1 , 0.1 ,- 0.1 )
 glTexCoord2f 0.0, 0.0: glVertex3f (- 0.1 , 0.1 ,  0.1 )
 glTexCoord2f 1.0, 0.0: glVertex3f (  0.1 , 0.1 ,  0.1 )
 
 glTexCoord2f 1.0, 1.0: glVertex3f (  0.1 ,- 0.1 ,  0.1 )
 glTexCoord2f 0.0, 1.0: glVertex3f (- 0.1 ,- 0.1 ,  0.1 )
 glTexCoord2f 0.0, 0.0: glVertex3f (- 0.1 ,- 0.1 ,- 0.1 )
 glTexCoord2f 1.0, 0.0: glVertex3f (  0.1 ,- 0.1 ,- 0.1 )
 
 glTexCoord2f 1.0, 1.0: glVertex3f (  0.1 ,  0.1 ,  0.1 )
 glTexCoord2f 0.0, 1.0: glVertex3f (- 0.1 ,  0.1 ,  0.1 )
 glTexCoord2f 0.0, 0.0: glVertex3f (- 0.1 ,- 0.1 ,  0.1 )
 glTexCoord2f 1.0, 0.0: glVertex3f (  0.1 ,- 0.1 ,  0.1 )
 
 glTexCoord2f 1.0, 1.0: glVertex3f (  0.1 ,- 0.1 ,- 0.1 )
 glTexCoord2f 0.0, 1.0: glVertex3f (- 0.1 ,- 0.1 ,- 0.1 )
 glTexCoord2f 0.0, 0.0: glVertex3f (- 0.1 ,  0.1 ,- 0.1 )
 glTexCoord2f 1.0, 0.0: glVertex3f (  0.1 ,  0.1 ,- 0.1 )
 
 glTexCoord2f 1.0, 1.0: glVertex3f (- 0.1 ,  0.1 ,  0.1 )
 glTexCoord2f 0.0, 1.0: glVertex3f (- 0.1 ,  0.1 ,- 0.1 )
 glTexCoord2f 0.0, 0.0: glVertex3f (- 0.1 ,- 0.1 ,- 0.1 )
 glTexCoord2f 1.0, 0.0: glVertex3f (- 0.1 ,- 0.1 ,  0.1 )
 
 glTexCoord2f 1.0, 1.0: glVertex3f (  0.1 ,  0.1 ,- 0.1 )
 glTexCoord2f 0.0, 1.0: glVertex3f (  0.1 ,  0.1 ,  0.1 )
 glTexCoord2f 0.0, 0.0: glVertex3f (  0.1 ,- 0.1 ,  0.1 )
 glTexCoord2f 1.0, 0.0: glVertex3f (  0.1 ,- 0.1 ,- 0.1 )
glEnd
 
r4X = r4X + 0.8
r4Y = r4Y + 0.6
r4Z = r4Z + 0.4

DoEvents
SwapBuffers hDc
SetFps 70
Wend
WinEnd

kryton9

  • Guest
Re: FreeGlut
« Reply #3 on: June 08, 2012, 04:11:59 PM »
Peter, your posts have nothing to do with freeglut. By the way, I get an error when compiling the triangle demo.

Charles, thanks a lot!!! Can't wait to play with it! Using this as a base, our code will be cross platform ready if ever needed.

http://freeglut.sourceforge.net/docs/api.php
« Last Edit: June 08, 2012, 07:07:51 PM by kryton9 »

kryton9

  • Guest
Compiles, but crashes
« Reply #4 on: June 08, 2012, 07:03:52 PM »
Charles, very excitedly I pulled out some old code. A couple years back I wrote the same app using Glut, SDL and WinApi to see the differences. I remember Glut was by the far the easiest back then.
So I happily translated the code to oxygen and got all the bugs compiling worked out in the code. Now I am stuck in that it crashes after showing up on the screen. I am at a loss and need the Oxygen Oracle's help when you get a chance. Thanks again for this great cross platform tool!

Everything you need is in the attachment. It will unzip into a folder to put in your projects folder in oxygen.

Commands: the a and z key zoom in and out, all arrow keys rotate the cube appropriately and escape to exit.

Updated: The crash is being caused by the glutTimerFunc, I commented out all of the stuff and one by one uncommented and it only crashes when I get to the glutTimerFunc.
I tried:
glutTimerFunc( 1, @timerLoop, )   shows cube crashes
glutTimerFunc( 1, @timerLoop, 0 )   shows cube crashes
glutTimerFunc( 1, @timerLoop(), 0 ) just crashes
glutTimerFunc( 1, @timerLoop(0), 0 ) just crashes
glutTimerFunc( 1, @timerLoop(),  ) just crashes
glutTimerFunc( 1, int @timerLoop,  )   shows cube crashes
glutTimerFunc( 1, int @timerLoop, 0 )   shows cube crashes
glutTimerFunc( 1, int @timerLoop(), 0 )  just crashes
glutTimerFunc( 1, int @timerLoop(0), 0 ) just crashes
glutTimerFunc( 1, int @timerLoop(),  ) just crashes

I commented out the glutTimerFunc and you see it runs without crashing, but need getTimerFunc to work for input and fps updates.
« Last Edit: June 08, 2012, 08:14:43 PM by kryton9 »

kryton9

  • Guest
Re: FreeGlut
« Reply #5 on: June 08, 2012, 08:06:37 PM »
I did update the last zip test file. I just added the test code commented out to make it easier to test.

Charles Pegge

  • Guest
Re: FreeGlut
« Reply #6 on: June 08, 2012, 08:16:36 PM »
Hi Kent, nice demo!

I discover that all the callbacks are cdecl

So the solution is to enclose them in an extern block:

extern cdecl
...
end extern


With the extern block, the callback tags are now redundant and may be removed from each function

Charles

kryton9

  • Guest
Re: FreeGlut
« Reply #7 on: June 08, 2012, 08:53:18 PM »
You are the Oracle, not of Delphi but Oxygen that is for sure! I was at a total loss after going through all the different ideas. Thanks so much, now I can work on this full throttle.
« Last Edit: June 08, 2012, 09:07:14 PM by kryton9 »

kryton9

  • Guest
Re: FreeGlut
« Reply #8 on: June 08, 2012, 08:59:56 PM »
I still have some problems to figure out, the escape, in and out keys are not working and the fps is not showing up. But I should be able to figure those out, I hope. Will upload the latest when figured it out. Thanks again for your help and this new addition!

Charles Pegge

  • Guest
Re: FreeGlut
« Reply #9 on: June 08, 2012, 09:28:18 PM »
The FPS should show up, but I set the decimal places to zero. Check you have the right Oxygen.dll in the Oxygen base directory.

If the lib is specified in the extern block, it covers all the declares within the block.

All the freeglut procs seem to be stdcall (unlike sqlite!) but the callbacks on your side have to be cdecl.

I checked Peter's code, and both examples work. But the aspect ratio and perspective projection are not working correctly. Mysterious, because I use the same algorithm.

Charles

kryton9

  • Guest
Re: FreeGlut
« Reply #10 on: June 08, 2012, 09:51:09 PM »
Charles I will download the latest, I just got it the other day. But just in case. Ok. Downloaded from the http://www.oxygenbasic.org/downloads.htm in progress download.
Still the same problem, no fps and the problem below is still happening.

Anyways, something is wrong, because the print statement is not working as you would think.
So I am bothering you again, because that means something else is lurking that I will never figure out.
Line 187.  

kryton9

  • Guest
Re: FreeGlut
« Reply #11 on: June 08, 2012, 11:09:29 PM »
I solved the a, z and escape key. I changed:
Code: OxygenBasic
  1. sub keyboardCB(unsigned char key, int x, int y)
  2.         keys[key] = 1
  3. end sub
  4.  
  5. sub keyboardUpCB(unsigned char key, int x, int y)
  6.         keys[key] = 0
  7. end sub

to:
Code: OxygenBasic
  1. sub keyboardCB(int key, int x, int y)
  2.     keys[key] = GL_TRUE
  3. end sub
  4.  
  5. sub keyboardUpCB(int key, int x, int y)
  6.         keys[key] = GL_FALSE
  7. end sub

But FPS is still not printing, so working on that.

kryton9

  • Guest
FPS problem
« Reply #12 on: June 08, 2012, 11:46:58 PM »
I traced it down to the "static" keyword. When you use it, it puts a strange value the first time. This will show the problem. Solution up to the master to figure out.
Code: OxygenBasic
  1. sub displayFPS()
  2.         ' this is assigned once because of the word static
  3.         static long lastTime = glutGet(GLUT_ELAPSED_TIME)
  4.  
  5.         ' this keeps track of the loops or frames
  6.         static long loops = 0
  7.  
  8.         ' we will average out the fps to make it less volatile in what it shows
  9.         static GLfloat fps = 0
  10.  
  11.         long newTime = glutGet GLUT_ELAPSED_TIME
  12.     long t = newTime - lastTime
  13.     glutSetWindowTitle str(lastTime) + "   " + str(newTime)
  14.         if t > 100 then
  15.                 GLfloat newFPS = loops / ( newTime - lastTime ) * 1000
  16.                 fps = ( fps + newFPS ) / 2
  17.                 string s = "FPS : " + str(fps,2)
  18.         glutSetWindowTitle s
  19.                 lastTime = newTime
  20.                 loops = 0
  21.         end if 
  22.         loops ++
  23. end sub

kryton9

  • Guest
Re: FreeGlut
« Reply #13 on: June 09, 2012, 12:19:26 AM »
This code below fixes it. It appears that when static is used, it doesn't clear the memory, my guess at least. This is not elegant but it shows that static is where the problem is happening when not initialized to 0 but another value first.

Code: OxygenBasic
  1. include "freeglut.inc"
  2. indexbase 0
  3.  
  4. 'function Main at the end of the file
  5.  
  6. ' GLOBAL VARIABLES
  7. 'escape to exit
  8. % GLUT_KEY_ESCAPE 27
  9. 'Arrow keys to rotate cube
  10. 'A zoom in
  11. % GLUT_KEY_IN 97
  12. 'Z zoom out
  13. % GLUT_KEY_OUT 122
  14.  
  15. sys flagOnceForLastTime = 0
  16.  
  17. const GLsizei windowWidth  = 1024
  18. const GLsizei windowHeight = 768
  19.  
  20. const GLfloat speed     = 1
  21. const GLfloat zoomSpeed = 0.05
  22.  
  23. GLfloat cubeRotateX = 45
  24. GLfloat cubeRotateY = 45
  25. GLfloat camMovZ     = -5
  26.  
  27. bool keys[255]
  28.  
  29. ' NON CALLBACK FUNCTIONS AND SUBS
  30. sub establishProjectionMatrix( GLsizei width, GLsizei height )
  31.         glViewport 0, 0, width, height
  32.         glMatrixMode GL_PROJECTION
  33.         glLoadIdentity
  34.         gluPerspective 45, ( width / height ), 0.1, 200
  35. end sub
  36.  
  37.  
  38. sub initGL( GLsizei width, GLsizei height )
  39.         establishProjectionMatrix width, height
  40.         glShadeModel GL_SMOOTH
  41.         glClearColor 0, 0, 0, 1
  42.         glEnable GL_DEPTH_TEST
  43.         glDepthFunc GL_LEQUAL
  44.         glHint GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST
  45.         glEnable GL_PERSPECTIVE_CORRECTION_HINT
  46. end sub
  47.  
  48. sub displayFPS()
  49.         static sys lastTime = 0
  50.     if flagOnceForLastTime = 0 then
  51.         lastTime = glutGet(GLUT_ELAPSED_TIME)
  52.         flagOnceForLastTime = 1
  53.     end if
  54.  
  55.         ' this keeps track of the loops or frames
  56.         static sys loops = 0
  57.  
  58.         ' we will average out the fps to make it less volatile in what it shows
  59.         static GLfloat fps = 0
  60.  
  61.         sys newTime = glutGet GLUT_ELAPSED_TIME
  62.     sys t = newTime - lastTime
  63.     'glutSetWindowTitle str(lastTime) + "   " + str(newTime) + "    t: " + str(t)
  64.         if t > 100 then
  65.                 GLfloat newFPS = loops / ( newTime - lastTime ) * 1000
  66.                 fps = ( fps + newFPS ) / 2
  67.                 string s = "FPS : " + str(fps,2)
  68.         glutSetWindowTitle s
  69.                 lastTime = newTime
  70.                 loops = 0
  71.         end if 
  72.         loops ++
  73. end sub
  74.  
  75. function checkKeys() as GLboolean
  76.         if keys[GLUT_KEY_ESCAPE] = GL_TRUE then
  77.                 return GL_TRUE
  78.     end if
  79.  
  80.         if keys[GLUT_KEY_LEFT] = GL_TRUE then
  81.                 cubeRotateY -= speed
  82.     end if
  83.        
  84.         if keys[GLUT_KEY_RIGHT] = GL_TRUE then
  85.                 cubeRotateY += speed
  86.     end if
  87.        
  88.         if keys[GLUT_KEY_UP] = GL_TRUE then
  89.                 cubeRotateX -= speed
  90.     end if
  91.  
  92.         if keys[GLUT_KEY_DOWN] = GL_TRUE then
  93.                 cubeRotateX += speed
  94.     end if
  95.  
  96.         if keys[GLUT_KEY_IN] = GL_TRUE then
  97.                 camMovZ += zoomSpeed
  98.     end if
  99.  
  100.         if keys[GLUT_KEY_OUT] = GL_TRUE then
  101.                 camMovZ -= zoomSpeed
  102.     end if     
  103.  
  104.         return GL_FALSE
  105. end function
  106.  
  107. '===========
  108. extern cdecl ' because of this syntax, no need to add callback to each sub or function below
  109. '===========
  110.  
  111. 'CALLBACK FUNCTIONS AND SUBS
  112.  
  113. ' by declaring and defining here, we don't need to do it twice
  114. sub drawSceneCB()
  115.  
  116.         ' for 3D we clear both bits, if 2D only the one on the left
  117.         glClear GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT
  118.  
  119.         glMatrixMode GL_MODELVIEW
  120.         glLoadIdentity()
  121.  
  122.         ' moves the camera back
  123.         glTranslatef 0, 0, camMovZ
  124.         glRotatef cubeRotateX, 1, 0, 0
  125.         glRotatef cubeRotateY, 0, 1, 0
  126.  
  127.         ' Draw cube
  128.         glBegin GL_QUADS
  129.                 ' top face
  130.                  glColor3f  1, 0.5,  0
  131.                 glVertex3f  1,   1, -1
  132.                 glVertex3f -1,   1, -1
  133.                 glVertex3f -1,   1,  1
  134.                 glVertex3f  1,   1,  1
  135.                 ' bottom face
  136.                  glColor3f  0,  1,  0
  137.                 glVertex3f  1, -1, -1
  138.                 glVertex3f -1, -1, -1
  139.                 glVertex3f -1, -1,  1
  140.                 glVertex3f  1, -1,  1
  141.                 ' front face
  142.                  glColor3f  1,  0, 0
  143.                 glVertex3f  1,  1, 1
  144.                 glVertex3f -1,  1, 1
  145.                 glVertex3f -1, -1, 1
  146.                 glVertex3f  1, -1, 1
  147.                 ' back face
  148.                  glColor3f  1,  1,  0
  149.                 glVertex3f  1,  1, -1
  150.                 glVertex3f -1,  1, -1
  151.                 glVertex3f -1, -1, -1
  152.                 glVertex3f  1, -1, -1
  153.                 ' left face
  154.                  glColor3f  0,  0,  1
  155.                 glVertex3f -1,  1,  1
  156.                 glVertex3f -1,  1, -1
  157.                 glVertex3f -1, -1, -1
  158.                 glVertex3f -1, -1,  1
  159.                 ' right face
  160.         glColor3f 1,  0,  1
  161.                 glVertex3f 1,  1,  1
  162.                 glVertex3f 1,  1, -1
  163.                 glVertex3f 1, -1, -1
  164.                 glVertex3f 1, -1,  1
  165.         glEnd
  166.         glFlush
  167.  
  168.         ' this line will change depending on which window interface
  169.         ' is being used. Like SDL and GLUT
  170.         glutSwapBuffers
  171.     displayFPS
  172. end sub
  173.  
  174. 'timerLoop must match glutTimerFunc's requirements
  175. sub timerLoopCB (int value)
  176.  
  177.         if checkKeys() = GL_TRUE then
  178.                 glutExit
  179.     end if
  180.  
  181.         ' glut will call the drawscene function when it ready
  182.         ' very important for this to be allowed
  183.         glutPostRedisplay
  184.  
  185.         ' by putting this here, we created a loop.
  186.         ' SDL doesn't need something like this
  187.         glutTimerFunc 1, @timerLoopCB, 0
  188. end sub
  189.  
  190. sub keyboardCB(int key, int x, int y)
  191.     keys[key] = GL_TRUE
  192. end sub
  193.  
  194. sub keyboardUpCB(int key, int x, int y)
  195.         keys[key] = GL_FALSE
  196. end sub
  197.  
  198. sub keyboardSpecialCB(int key, int x, int y)
  199.         keys[key] = GL_TRUE
  200. end sub
  201.  
  202. sub keyboardSpecialUpCB(int key, int x, int y)
  203.         keys[key] = GL_FALSE
  204. end sub
  205.  
  206. '=========
  207. end extern
  208. '=========
  209.  
  210. function main(int argc, char **argv) as sys
  211.  
  212.         ' initialize glut, passing the above parameters to gluInit
  213.         glutInit argc, argv
  214.         ' enable double frame buffering, so we don't get flicker
  215.        glutInitDisplayMode GLUT_DOUBLE
  216.  
  217.         sys windowID = glutCreateWindow "OpenGL FreeGlut Cube Demo"
  218.         ' by default, glut knows the last window used,
  219.        'so we can resize it after we create it
  220.        glutReshapeWindow windowWidth, windowHeight
  221.        
  222.         ' our procedure
  223.        initGL windowWidth, windowHeight
  224.  
  225.         glutDisplayFunc    @drawSceneCB
  226.         glutKeyboardFunc   @keyboardCB
  227.         glutKeyboardUpFunc @keyboardUpCB
  228.         glutSpecialFunc    @keyboardSpecialCB
  229.         glutSpecialUpFunc  @keyboardSpecialUpCB
  230.         glutTimerFunc 1,   @timerLoopCB, 0
  231.        
  232.         ' this goes to the main loop and stays there till the end
  233.        glutMainLoop
  234.         'should never get here, but just in case
  235.         return 0
  236. end function
  237.  
  238. ' THIS IS THE PROGRAM
  239. main null,null
  240. '====================
« Last Edit: June 09, 2012, 01:08:02 AM by kryton9 »

Aurel

  • Guest
Re: FreeGlut
« Reply #14 on: June 09, 2012, 03:22:50 AM »
i don't know much about game engines but as i said ,i tried HGE and seems to me that
work fine and compile fine under EB.So what about HGE ?