开发者

Choppy SDL+OpenGL animation when vsync is on

Uint32 prev = SDL_GetTicks();

while ( true )
{
    Draw();

    Uint32 now = SDL_GetTicks();
    Uint32 delta = now - prev;
    printf( "%u\n" , delta );
    Update( d开发者_C百科elta / 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.


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();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜