如何在另一个函数中调用显示回调函数,以便我的计时器函数也可以执行?
我有一个绘制圆的显示函数,并且有一个更新函数,使用它沿 y 轴移动圆。一旦圆圈到达窗口底部,我想在顶部绘制一个新圆圈,并以与前一个圆圈相同的方式移动该圆圈。 我该怎么做?
void display(void)
{
int i;
flag=0;
glPointSize(2.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
disp2();
glFlush();
}
void update(int a)
{
if(y1center>=100)
{
y1center-=5;
glutPostRedisplay();
glutTimerFunc(40,update,0);
}
else
{
y1center=950;
glutDisplayFunc(display);
//glutPostRedisplay();
display();
}
}
这是我尝试在更新功能中执行的操作,但没有成功。它只是在顶部画了一个新圆圈,但该圆圈没有移动。 disp2() 绘制圆
I have a display function that draws a circle and i have an update function using which i move the circle along the y axis. Once the circle reaches the bottom of the window i want to draw a new circle at the top and move that circle in the same manner as the previous one..
How do i do this?
void display(void)
{
int i;
flag=0;
glPointSize(2.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
disp2();
glFlush();
}
void update(int a)
{
if(y1center>=100)
{
y1center-=5;
glutPostRedisplay();
glutTimerFunc(40,update,0);
}
else
{
y1center=950;
glutDisplayFunc(display);
//glutPostRedisplay();
display();
}
}
This is what i tried to do in the update function but it did'nt work. It just drew a new circle at the top but that circle doesn't move..
disp2() draws the circle
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它可能会失败,因为您的更新函数没有告诉 glut 在 40 毫秒内再次调用更新函数(glutTimerFunc),因此一旦它进入 else 状态,更新函数就不再执行任何操作。
无论如何,我做了一些小修改,这应该使这项工作改变/创建以下更新功能:
It probably fails because your update function doesn't tell glut to call the update function again in 40 ms (glutTimerFunc), so once it's been in the else once the update function doesn't do anything anymore.
Anyway I've made a few small modifications, which should make this work change/create the following update function:
在 update 函数中,如果您陷入 else (y1center < 100) 中,您将不会再次注册计时器( glutTimerFunc(40,update,0) 调用)。
In update function, if you fall in the else (y1center < 100), you won't register the timer again (the glutTimerFunc(40,update,0) call).