Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/freeglut.h> //uses freeGLUT extensions!
- #include <iostream>
- //switches between manual looping or GLUT's default event loop//////////////////
- #define CUSTOMLOOP 1
- #if CUSTOMLOOP == 1
- #define MAINLOOP while (1) glutMainLoopEvent()
- #endif
- #if CUSTOMLOOP == 0
- #define MAINLOOP glutMainLoop()
- #endif
- ////////////////////////////////////////////////////////////////////////////////
- //display function
- void cback_render()
- {
- static float rotations = 0;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- glRotatef(rotations, 0, 0, 1);
- glBegin(GL_TRIANGLES);
- glVertex3f(0,0,0);
- glVertex3f(1,0,0);
- glVertex3f(0,1,0);
- glEnd();
- glutSwapBuffers();
- if (++rotations > 360) rotations -= 360;
- //glutMainLoopEvent() never returns unless you force an update!!!
- #if CUSTOMLOOP == 1
- glutPostRedisplay();
- #endif
- }
- int main(int argc, char **argv)
- {
- glutInit(&argc, argv);
- glutInitDisplayMode(GLUT_DOUBLE | GLUT_DEPTH);
- glutInitWindowPosition(100, 100);
- glutInitWindowSize(512, 512);
- glutCreateWindow("freegluttest");
- glutDisplayFunc (cback_render);
- //Don't need to provide an idle function if we're forcing redisplays ourselves
- #if CUSTOMLOOP == 0
- glutIdleFunc(cback_render);
- #endif
- //loop switch occurs here
- MAINLOOP;
- return 0;
- }
Add Comment
Please, Sign In to add comment