opengl + glut glutPostRedisplay在哪里? [英] opengl+glut glutPostRedisplay where?

查看:154
本文介绍了opengl + glut glutPostRedisplay在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用GLUT和OPENGL在C语言中进行编程,我希望窗口一次又一次地重新绘制自身。我知道,如果我将它放在Glut的空闲函数中,则我的PC滞后了,我可以使用 glutPostRedisplay()重新渲染。

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.

我的代码遵循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 don't quite understand your question... what do yo mean "you want your window redrawing itself again and again" ?

GLUT本身用glutMainLoop来做到这一点()函数不断调用显示回调函数(通常问题是相反的……人们问他们如何以编程方式离开无限循环..这对于GLUT是不可能的,但对于FreeGLUT则不可能)

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...

这篇关于opengl + glut glutPostRedisplay在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆