Guest User

FreeGLUT glutMainLoopEvent() problem

a guest
Sep 22nd, 2010
414
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.31 KB | None | 0 0
  1. #include <GL/freeglut.h> //uses freeGLUT extensions!
  2.  
  3. #include <iostream>
  4.  
  5. //switches between manual looping or GLUT's default event loop//////////////////
  6. #define CUSTOMLOOP 1
  7.  
  8. #if CUSTOMLOOP == 1
  9.     #define MAINLOOP while (1) glutMainLoopEvent()
  10. #endif
  11.  
  12. #if CUSTOMLOOP == 0
  13.     #define MAINLOOP glutMainLoop()
  14. #endif
  15. ////////////////////////////////////////////////////////////////////////////////
  16.  
  17. //display function
  18. void cback_render()
  19. {
  20.     static float rotations = 0;
  21.  
  22.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  23.  
  24.     glLoadIdentity();
  25.     glRotatef(rotations, 0, 0, 1);
  26.  
  27.     glBegin(GL_TRIANGLES);
  28.         glVertex3f(0,0,0);
  29.         glVertex3f(1,0,0);
  30.         glVertex3f(0,1,0);
  31.     glEnd();
  32.  
  33.     glutSwapBuffers();
  34.  
  35.     if (++rotations > 360) rotations -= 360;
  36.  
  37. //glutMainLoopEvent() never returns unless you force an update!!!
  38. #if CUSTOMLOOP == 1
  39.     glutPostRedisplay();
  40. #endif
  41. }
  42.  
  43. int main(int argc, char **argv)
  44. {
  45.     glutInit(&argc, argv);
  46.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
  47.     glutInitWindowPosition(100, 100);
  48.     glutInitWindowSize(512, 512);
  49.  
  50.     glutCreateWindow("freegluttest");
  51.     glutDisplayFunc (cback_render);
  52.  
  53. //Don't need to provide an idle function if we're forcing redisplays ourselves
  54. #if CUSTOMLOOP == 0
  55.     glutIdleFunc(cback_render);
  56. #endif
  57.  
  58.     //loop switch occurs here
  59.     MAINLOOP;
  60.  
  61.     return 0;
  62. }
Add Comment
Please, Sign In to add comment