I have the following code
int i = 0;
void display(void)
{
glLoadIdentity();
glColor3f(1.0f, 0.0f, 0.0f);
glPushMatrix();
glTranslatef(20.0f, 20.0f, -40.f);
glRotatef(180.f, 0.0, 0.0, 1.0);
glBegin(GL_TRIANGLES);
glVertex3f(pts[tri[i]], (pts[ptsLength/2 + tri[i]] - maximum) * -1, 0);
glVertex3f(pts[tri[i+1]], (pts[ptsLength/2 + tri[i+1]] - maximum) * -1, 0);
glVertex3f(pts[tri[i+2]], (pts[ptsLength/2 + tri[i+2]] - maximum) * -1, 0);
glEnd();
i+=3;
glPopMatrix();
glutSwapBuffers();
}
How can I make this method pause and wait for a keystroke before rendering the next triangle?
Is this the
glutIdleFunc, or the one called when youglutPostRedisplay?In either case, you need to first setup a
glutKeyboardFunc, in which you detect whether a certain key is pressed or not.In the case you update the screen only on certain events:
In the case you are using
displayas the idle function, you can do:Side note: It is best to keep the logic and rendering separate. So perhaps a code like this is best:
Note that this way, you can make the
process_event_next_triangleas complicated as you want without affecting thedisplayfunction. This makes life much easier when you have many keys doing different stuff.