void init(void)
{
glEnable(GL_DEPTH_TEST);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
}
void display(void)
{
glClearColor(1.0, 1.0, 1.0, 1.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glScalef(1.0,1.0,1.0);
glColor3f(0.0,0.0,0.0);
glBegin(GL_POLYGON);
glVertex2f(-0.5, -0.5);
glVertex2f(-0.5, 0.5);
glVertex2f(0.5, 0.5);
glVertex2f(0.5, -0.5);
glEnd();
glutSwapBuffers();
}
void reshape(int w, int h)
{
int height = h;
int width = w;
glViewport(0, 0, (GLsizei)w, (GLsizei)h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60, (GLfloat)w / (GLfloat)h, 1.0, 100.0);
glMatrixMode(GL_MODELVIEW);
}
int main(int argc, char* argv[])
{
Complex c(0,0);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutInitWindowSize(512, 512);
glutInitWindowPosition(100, 100);
winID = glutCreateWindow("Fractal");
init();
glutDisplayFunc(display);
glutIdleFunc(display);
glutReshapeFunc(reshape);
// Compute the update rate here...
glutMainLoop();
return 0;
}
I get a square if I put the code in display(), except the glutSwapBuffers() in if condition which checks whether the code has entered display the first time. If I remove the if, I get a white window
// Compute the update rate here…
no it doesn't. That particular line of code is reached exactly one time in course of running the program. If you have a nonterminating loop there, you'll not reach the GLUT main loop, hence preventing events being processed. Also instead ofdisplay
you should registerglutPostRedisplay
as idle function if you want continous updates. – datenwolf