opengl+glut glutPostRedisplay在哪里?
我正在使用 GLUT 和 OPENGL 用 C 进行编程,我希望我的窗口能够一次又一次地重新绘制。我知道如果我将其放入 Glut 的空闲函数中,我可以使用 glutPostRedisplay() 重新渲染,但我的电脑会出现延迟。
我的代码遵循 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);
...
}
I'm programming in C with GLUT and OPENGL, i want my window redrawing itself again and again. I know that i can rerender with glutPostRedisplay()
, if I put it in the idle function of Glut my pc lags.
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);
...
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
Try this:
在 glutPostRedisplay 之前的时间片上使空闲产生任何剩余的 CPU 周期:
Make idle yielding any left CPU cycles on the time slice right before the glutPostRedisplay:
我不太明白你的问题......你是什么意思“你希望你的窗口一次又一次地重新绘制自己”?
GLUT 使用 glutMainLoop() 函数自行完成此操作,该函数不断调用显示回调函数(通常问题是相反的...人们问如何以编程方式离开无限循环..这对于 GLUT 是不可能的,但对于 FreeGLUT 则不然)
无需将重新显示放在空闲函数中,该函数仅在没有其他事情发生时调用...
I don't quite understand your question... what do yo mean "you want your window redrawing itself again and again" ?
GLUT does that itself with the glutMainLoop() function that keeps calling the display call back function (Usually the problem is the reversed... people ask how they can leave the infinite loop programmatically.. which is impossible with GLUT, but not with FreeGLUT)
No need to put the redisplay in the idle function, which is only called when nothing else is happening...