Opengl + glut glutPostRedisplay where?

I am programming in C with GLUT and OPENGL, I want my window to redraw again. I know that I can reerender with glutPostRedisplay() if I put it in an idle Glut my pc lags function.

My code is following atm

 void on_idle() { glutPostRedisplay(); } void on_draw() { ... glClearColor(1.f, 1.f, 1.f, 1.f); glClear(GL_COLOR_BUFFER_BIT); ... glFlush(); } int main(int argc, char** argv) { ... glutDisplayFunc(&on_draw); glutIdleFunc(&on_idle); ... } 
0
c draw opengl glut
source share
3 answers

Try the following:

 void on_timer(int value) { glutPostRedisplay(); glutTimerFunc(33, on_timer, 0); } void on_draw() { ... glClearColor(1.f, 1.f, 1.f, 1.f); glClear(GL_COLOR_BUFFER_BIT); ... glFlush(); } int main(int argc, char** argv) { ... glutDisplayFunc(on_draw); glutTimerFunc(33, on_timer, 0) ... } 
0
source share

Make downtime by giving any left processor cycles on the timeline right before glutPostRedisplay:

 void on_idle() { #ifdef WIN32 Sleep(0); // zero sleep = yield #else ifdef _POSIX_PRIORITY_SCHEDULING sched_yield(); // #include <sched.h> #endif glutPostRedisplay(); } 
0
source share

I don’t quite understand your question ... what does it mean "do you want your window to be redrawn again and again"?

GLUT does this with the glutMainLoop () function, which continues to call the display callback function (usually the problem is the opposite ... people ask how they can programmatically refuse an infinite loop .. which is impossible with GLUT, but not with FreeGLUT)

No need to redraw in an unoccupied function that is called only when nothing happens ...

0
source share

All Articles