使用 LWJGL 避免闪烁
在 Java Rubik's Cube 应用程序的上下文中,我尝试为最终用户执行的立方体操作设置动画。
为此,我只使用旋转和多次重绘,如下所示:
GL11.glRotatef(zRotate, 0.0f, 0.0f, 1.0f);
zRotate 变量从 0 递增到 90,并且每 20 毫秒执行一次重绘。
它工作完美,但我看到屏幕上闪烁..我怎样才能避免这种情况?
In the context of a Java Rubik's Cube application I am trying to animate the cube actions performed by the end user.
To do that I am just using rotations and many redraws as following:
GL11.glRotatef(zRotate, 0.0f, 0.0f, 1.0f);
the zRotate variable is icremented from 0 to 90 and I am performing redraws every 20 miliseconds.
It works perfectly but I see flickering on the screen .. How can I avoid that ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据 此帖子,您可以调用
Display.setVSyncEnabled(true );
在初始化期间。According to this thread, You could call
Display.setVSyncEnabled(true);
during initialization.解决方案是在 Opengl 画布创建中添加 SWT.NO_BACKGROUND 样式。
The solution was to add the SWT.NO_BACKGROUND style in the Opengl canvas creation.
使用双缓冲。
http://en.wikipedia.org/wiki/Double_buffer#Double_buffering_in_computer_graphics
我没有任何使用 LWJGL 的经验,但一种常见的技术是绘制位图并用位图一步重绘屏幕/窗口。
Use Double buffering.
http://en.wikipedia.org/wiki/Double_buffer#Double_buffering_in_computer_graphics
I dont have any experience with LWJGL, but a common technique is to draw into a bitmap and to redraw the screen/window with the bitmap in one step.