垂直同步开启时,SDL+OpenGL 动画断断续续

发布于 2024-11-11 15:28:10 字数 564 浏览 1 评论 0原文

Uint32 prev = SDL_GetTicks();

while ( true )
{
    Draw();

    Uint32 now = SDL_GetTicks();
    Uint32 delta = now - prev;
    printf( "%u\n" , delta );
    Update( delta / 1000.0f );
    prev = now;

    ProcessEvents();
}

该应用程序是一个简单的移动方块。我的循环看起来像这样,当垂直同步时,整个事情运行得非常顺利;关闭它会导致动画发生某种跳跃。我插入了一些打印内容,这就是我发现的内容:

[...]
16
15
16
66 #
2  #
0  #
0  #
16
16
21
[...]

我知道这种循环存在几个问题,但它们似乎都不适用于这个简单的示例(我错了吗?)。是什么导致了这种行为?我该如何克服它?

我在 Linux 系统上使用 ATI 卡,但我期待一个可移植的解释/解决方案。

Uint32 prev = SDL_GetTicks();

while ( true )
{
    Draw();

    Uint32 now = SDL_GetTicks();
    Uint32 delta = now - prev;
    printf( "%u\n" , delta );
    Update( delta / 1000.0f );
    prev = now;

    ProcessEvents();
}

The application is a simple moving square. My loop looks like that and when vsync is on the whole thing just runs quite smoothly; turning it off instead causes some kind of jumps of the animation. I've inserted some prints and here's what I've found:

[...]
16
15
16
66 #
2  #
0  #
0  #
16
16
21
[...]

I know there are several issues with this kind of loop but none of them seem to apply to this simple example (am I wrong?). What causes this behavior and how can I overcome it?

I'm using an ATI card on a Linux system, but I'm expecting a portable explanation/solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

请持续率性 2024-11-18 15:28:10

似乎缺少 glFinish(),我在某处读到对该函数的调用在大多数情况下是无用的(此处此处例如)。好吧,我可能误解了一些基本概念,但这对我有用,现在 Draw() 函数以:

    [...]
    glFinish();
    SDL_GL_SwapBuffers();
}

It seems that it was a lack of glFinish(), I've read somewhere that calls to that function are in most cases useless (here or here for example). Well, I'm maybe misunderstanding some fundamental concepts but that worked for me and now the Draw() function ends with:

    [...]
    glFinish();
    SDL_GL_SwapBuffers();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文