Java 双缓冲 - 仅每隔一帧绘制
我正在尝试开发一个全屏应用程序,但我遇到了双缓冲区问题。
public void create ()
{
window = new JWindow ();
window.setIgnoreRepaint (true);
GraphicsEnvironment.getLocalGraphicsEnvironment ().getDefaultScreenDevice ().setFullScreenWindow (window);
window.setVisible (true);
window.createBufferStrategy (2);
}
public void renderCycle ()
{
BufferStrategy strategy = window.getBufferStrategy ();
while (true)
{
render ((Graphics2D) strategy.getDrawGraphics ());
strategy.show ();
}
}
public void render (Graphics2D g)
{
g.setColor (Color.WHITE);
g.drawString ("Veikia", 100, 100);
}
我看到严重的闪烁 - 似乎文本仅在每个其他缓冲区上绘制,而其余缓冲区包含白色背景。可能是什么问题?
I'm trying to develop a full-screen application, but I'm having issues with double buffers.
public void create ()
{
window = new JWindow ();
window.setIgnoreRepaint (true);
GraphicsEnvironment.getLocalGraphicsEnvironment ().getDefaultScreenDevice ().setFullScreenWindow (window);
window.setVisible (true);
window.createBufferStrategy (2);
}
public void renderCycle ()
{
BufferStrategy strategy = window.getBufferStrategy ();
while (true)
{
render ((Graphics2D) strategy.getDrawGraphics ());
strategy.show ();
}
}
public void render (Graphics2D g)
{
g.setColor (Color.WHITE);
g.drawString ("Veikia", 100, 100);
}
I see a heavy flickering - it seems as if the text is drawn only on every other buffer and remaining buffers contain white background. What could be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚尝试过这个
MultiBufferTest
。直到滞后
周期低于显示器相应的刷新率之前,我没有看到任何渲染伪影。您的示例似乎在帧之间没有延迟。我添加了几行来显示帧周期:
I just tried this
MultiBufferTest
. I didn't see any rendering artifact until thelag
period fell below the monitor's corresponding refresh rate. Your example appears to have no delay between frames.I added a few lines to show the frame period: