gpt4 book ai didi

c++ - 如何使用opengl使点闪烁?

转载 作者:行者123 更新时间:2023-11-28 06:05:50 26 4
gpt4 key购买 nike

我对使用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。

最佳答案

您应该使用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();
}

关于c++ - 如何使用opengl使点闪烁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32428512/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com