c ++ opengl:sleep()在动画期间不会影响glutPostRedisplay() [英] c++ opengl: sleep() does not affect glutPostRedisplay() during an animation

查看:1597
本文介绍了c ++ opengl:sleep()在动画期间不会影响glutPostRedisplay()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个球体画在屏幕上。当我按下一个按钮,我想让球慢慢地向右移动。我试图用

  for(int i = 0; i <10; i ++)
{
sphere.moveToRight(0.1);
glutPostRedisplay();
sleep(1000);
}

但是它不是动画,而是等待几秒钟,然后绘制球体最终位置。我认为是因为睡眠停止了glutPostRediplay()。任何想法如何完成这个基本annimation?

解决方案

您使用 glutPostRedisplay 错误。
$ b

结帐: http:// www .opengl.org / resources / libraries / glut / spec3 / node20.html


glutPostRedisplay 标记当前窗口的正常平面,因为需要重新显示
glutPostWindowRedisplay 工作指定的窗口
需要重新显示。在调用之后,下一次迭代
glutMainLoop ,窗口的显示回调将被调用到
重新显示窗口的法线平面。在下一个显示回调机会之前多次调用
glutPostRedisplay
只生成一个重新显示回调。 glutPostRedisplay 可能是
在窗口的显示或覆盖显示回调中调用
重新标记该窗口以重新显示。


这意味着10秒后您的图片将刷新一次。


I have a sphere drawn on the screen. When I press a button I want the sphere to slowly move to the right. I am trying to accomplish this with

for (int i = 0;i<10;i++)
{
sphere.moveToRight(0.1);
glutPostRedisplay();
sleep(1000);
}

But instead of animated, it waits a few seconds and then draws the sphere in the final location. I assume it is because sleep is stopping the glutPostRediplay(). Any ideas of how to accomplish this basic annimation?

解决方案

You are using glutPostRedisplay wrong.

Check out: http://www.opengl.org/resources/libraries/glut/spec3/node20.html

glutPostRedisplay marks the normal plane of current window as needing to be redisplayed. glutPostWindowRedisplay works the specified window as needing to be redisplayed. After either call, the next iteration through glutMainLoop, the window's display callback will be called to redisplay the window's normal plane. Multiple calls to glutPostRedisplay before the next display callback opportunity generates only a single redisplay callback. glutPostRedisplay may be called within a window's display or overlay display callback to re-mark that window for redisplay.

Which means, after 10 seconds your image will get refreshed once.

这篇关于c ++ opengl:sleep()在动画期间不会影响glutPostRedisplay()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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