如何使用opengl使点闪烁?

时间:2015-09-06 21:33:11

标签: c++ visual-studio opengl animation

我在使用Opengl方面非常新,并且很难尝试让几个点眨眼一秒左右。我已经设法弄清楚如何使用箭头键输入,但我没有任何运气搞清楚这一点。

我尝试过Sleep()函数,但这个函数不能替代动画。我无法找到我应该如何修复我的glutidle()以使其工作。

在我的window.cpp中,

void Appwindow::buildObject(){ }, i have several          
_ptcoords.push_back(GsVec(-0.53 + xxx, 0.1 + yyy, 0.0));
_ptcolors.push_back(GsColor::yellow);
//and 15 of this points or mores. 

我已经在线阅读,发现我必须调整我的帧,对于大多数标准计算机,它将设置为60 fps。

1 个答案:

答案 0 :(得分:1)

您应该使用glutTimerFunc()定期调用子例程。在这个子程序中你保持你的动画参数,可以调用glutPostRedisplay()来调用你的主绘图函数。

然后,在您的主绘图功能中,只需在您希望它们出现的时候绘制点。

int time;
float speed = 0.1f; // 10 frames per second

void animate(int value) {
    glutTimerFunc(speed, animate, 0);
    time++;
    if (time >= 10)
        time = 0;        // time is in tenths of a second
    glutPostRedisplay();
}

void display() {
    if (time > 5) {
        // draw your flashing points here
    }
    // draw anything that doesn't flash here
 }

int main(void) {int argc, char *argv[]) {

    // your glut init goes here

    glutTimerFunc(1.0, animate, 0);
    glutDisplayFunc(display);
    glutTimerFunc(TIMERSECS, animate, 0);
    glutPostRedisplay();

    glutMainLoop();
}