Hello everyone, I met with a strangle problem in a demo program to lean double buffering of OpenGL. I specified GLUT_DOUBLE in glutInitDisplayMode and called glutSwapBuffers at the end of display callback. But the result is exactly the same without GLUT_DOUBLE and glutSwapBuffers, so what is wrong with my codes, could anyone help me out of this?
Here is the code, spinning a square continuously on the screen:
#include <stdio.h>
#include <GLUT/GLUT.h>
#include <math.h>
float theta = 0;
void display ();
void idle ();
void mouse (int button, int state, int x, int y);
int main (int argc, char** argv)
{
glutInit (&argc, argv);
glutInitDisplayMode (GLUT_DOUBLE |GLUT_RGB);
glutInitWindowPosition (100, 100);
glutInitWindowSize (500, 500);
glutCreateWindow ("Double Buffer Testing");
glutDisplayFunc (display);
glutIdleFunc(idle);
glClearColor (1, 1, 1,1);
glMatrixMode (GL_PROJECTION);
glLoadIdentity ();
gluOrtho2D (-1, 1, -1, 1);
glMatrixMode (GL_MODELVIEW);
glutMainLoop();
return 0;
}
void display ()
{
glClear (GL_COLOR_BUFFER_BIT);
glColor3f (1, 0, 0);
glBegin (GL_POLYGON);
float thetar = theta * (3.14159 / 180.0);
glVertex2f (cosf (thetar), sinf (thetar));
glVertex2f (-sinf (thetar), cosf(thetar));
glVertex2f (-cosf (thetar), -sinf (thetar));
glVertex2f (sinf (thetar), -cosf (thetar));
glEnd ();
glutSwapBuffers();
}
void idle ()
{
theta += 2;
if (theta > 360) theta -= 360;
glutPostRedisplay ();
}