Java 双缓冲 - 仅每隔一帧绘制

发布于 2024-12-19 04:48:29 字数 701 浏览 2 评论 0原文

我正在尝试开发一个全屏应用程序,但我遇到了双缓冲区问题。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不再让梦枯萎 2024-12-26 04:48:29

我刚刚尝试过这个 MultiBufferTest。直到滞后周期低于显示器相应的刷新率之前,我没有看到任何渲染伪影。您的示例似乎在帧之间没有延迟。

我添加了几行来显示帧周期:

...
g.fillRect(0, 0, bounds.width, bounds.height);
g.setColor(Color.black); // added
g.drawString(String.valueOf(lag), 100, 100); // added
bufferStrategy.show();
...

I just tried this MultiBufferTest. I didn't see any rendering artifact until the lag 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:

...
g.fillRect(0, 0, bounds.width, bounds.height);
g.setColor(Color.black); // added
g.drawString(String.valueOf(lag), 100, 100); // added
bufferStrategy.show();
...
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文