Still have tearing with double buffering

I’m using Linux, XFree 4.0.3, SDL 1.2.2 and OpenGL, and I’ve setup double
buffering, and yet I still am getting tearing. This is using an NVidia
GeForce2 DDR with the latest driver. (glxinfo shows I’ve got hardware
acceleration.) I set up double buffering with

SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER,1);

and then I set my video mode using

SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE | SDL_HWACCEL | SDL_OPENGL )

Using SDL_GL_GetAttribute shows that I did get double buffering. This
problem also rears its head if I set the video mode to use fullscreen.

Perhaps the problem lies herein: My monitor is being refreshed at 85 Hz.
My frames per second calculations show about 265Hz. How can this be
possible if SDL_GL_SwapBuffers() waits for the vertical blanking interval
before swapping? If it’s not waiting for the blanking interval, how can I
tell it to do so?

I can explain the tearing or the rest of my program in more detail if this
isn’t enough.

Any solution (including dropping SDL) will be very appreciated!

Thanks,
Andrew Straw

You could also limit the frames drawn per second with code like:

Uint32 lastticks=0;
Uint32 tick=0;
Uint32 delta_tick=0;

//Timer stuff
  tick = SDL_GetTicks();
  delta_tick = tick - lastticks;
  lastticks = tick;

  //limit to 40 revolutions per second (40*25ms = 1 second)
  if(delta_tick < 25)
    {
      SDL_Delay(25 - delta_tick);
      tick = SDL_GetTicks();
      delta_tick = delta_tick + tick - lastticks;
      lastticks = tick;
    }

I forget who’s code that came from, it was located somewhere in the mailing
list (possibly months ago) or on a webpage linked from the mailing list.

However this doesn’t solve the wait for vsync problem.

You may want to check if there is a configuration for the video driver that
will lock to vsync.

BTW this line:

SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE | SDL_HWACCEL | SDL_OPENGL )

Doesn’t need the SDL_HWSURFACE | SDL_HWACCEL flags (as they are for the 2D
api) if you are only using OpenGL. You only need the fullscreen flag for
fullscreen.

In the NVidia linux driver README file, it says to set the environment
variable __GL_SYNC_TO_VBLANK to a non-zero value.

It works! (But it doesn’t seem very portable.)

I’m using Linux, XFree 4.0.3, SDL 1.2.2 and OpenGL, and I’ve setup double
buffering, and yet I still am getting tearing. This is using an NVidia
GeForce2 DDR with the latest driver. (glxinfo shows I’ve got hardware
acceleration.) I set up double buffering with

SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER,1);

and then I set my video mode using

SDL_SetVideoMode(640, 480, 0, SDL_HWSURFACE | SDL_HWACCEL | SDL_OPENGL )

Using SDL_GL_GetAttribute shows that I did get double buffering. This
problem also rears its head if I set the video mode to use fullscreen.

Perhaps the problem lies herein: My monitor is being refreshed at 85 Hz.
My frames per second calculations show about 265Hz. How can this be
possible if SDL_GL_SwapBuffers() waits for the vertical blanking interval
before swapping? If it’s not waiting for the blanking interval, how can I
tell it to do so?

I can explain the tearing or the rest of my program in more detail if this
isn’t enough.

From the nvidia-driver readme:
__GL_SYNC_TO_VBLANK
Setting this to a non-zero value will force glXSwapBuffers
to sync to your monitor’s vertical refresh rate (perform
a swap only during the vertical blanking period).

I think you should try this option to force waiting for a vsync.
I have the same tearing with UT on my TNT.

HTH

Pius II.