How do I turn on Vsync?

Im using OpenGL for 3D, Linux, and SDL.

How what code do I use to turn on VSync from within the program. I can’t
seem to find any documentation on it.

I have seen this GL_SYNC_TO_VBLANK

But I don’t know how to enable it.

If anyone has information, related to this I would really apreciate it!

Thanks,
-Mike

MC wrote:

Im using OpenGL for 3D, Linux, and SDL.

How what code do I use to turn on VSync from within the program. I can’t
seem to find any documentation on it.

I have seen this GL_SYNC_TO_VBLANK

But I don’t know how to enable it.

If anyone has information, related to this I would really apreciate it!

If your shell is bash :
export __GL_SYNC_TO_VBLANK=1

or if you use a csh-style shell :
setenv __GL_SYNC_TO_VBLANK 1

Stephane

WOW!

I did this, and now my textures won’t load. I didn’t change a bit of my
code, didn’t move anything, but IMG_Load now dosn’t load any of my
textures!

What the hey?

Any clue as to what may be the cause?

-Mike

P.S. I tried removing the GL_SYNC variable thrugh export -n, didn’t
work. My textures will not load nowOn Wed, 2003-10-08 at 18:11, Stephane Marchesin wrote:

MC wrote:

Im using OpenGL for 3D, Linux, and SDL.

How what code do I use to turn on VSync from within the program. I can’t
seem to find any documentation on it.

I have seen this GL_SYNC_TO_VBLANK

But I don’t know how to enable it.

If anyone has information, related to this I would really apreciate it!

If your shell is bash :
export __GL_SYNC_TO_VBLANK=1

or if you use a csh-style shell :
setenv __GL_SYNC_TO_VBLANK 1

Stephane

He said “from within the program”. Windows has a simple GL extension
for this, but X drivers make you bend over backwards.

You might try setting these variables with putenv(). Be sure to do so
before initializing video.On Thu, Oct 09, 2003 at 12:11:08AM +0200, Stephane Marchesin wrote:

How what code do I use to turn on VSync from within the program. I can’t
seem to find any documentation on it.

If your shell is bash :
export __GL_SYNC_TO_VBLANK=1


Glenn Maynard

MC wrote:

Im using OpenGL for 3D, Linux, and SDL.

How what code do I use to turn on VSync from within the program. I can’t
seem to find any documentation on it.

I have seen this GL_SYNC_TO_VBLANK

But I don’t know how to enable it.

If anyone has information, related to this I would really apreciate it!

Oh yeah, and if I read the question completely and see “from within the
program” the answer becomes :
putenv("__GL_SYNC_TO_VBLANK=1");

Btw this is one of the least portable things to do, but hey you asked
for it :slight_smile:

Stephane

Hmmm… I restarted the Xserver and it seemed to fix the problem. Odd.

-Mike

Darn,

This vertical synk thing dosn’t seem to work at all, I still experience
a great amount of tearing in my game. Under windows, I don’t have this
problem. Is it linux speciffic, is v-syncing not supported?

-Mike

Tearing in a fixed area of the screen, possibly…? If so, that’s
because of the way most drivers implement page “flipping” on XFree86.

It’s actually driver specific - although XFree86 isn’t exactly helpful
when it comes to implementing this feature in drivers.

As it is, most OpenGL drivers render into an off-screen buffer which
is then copied to the screen with a h/w blit. Doing that without
tearing requires careful coding; make sure the blitter is ready to
start instantly before doing the retrace sync, and DO NOT blit rows
from the bottom to the top. Also, sync as early as possible; ie at
the start of the retrace; not the end. All drivers I’ve seen so far
get one or more of those things wrong. For reliable results, you also
need a real time OS, since timing is very critical, compared to
doing it with h/w pageflipping.

The proper method is to set up N h/w pages (N > 1) and just swap
pointers some time after sync’ing with the retrace. (Which is what
most Windows drivers do.) Nothing happens until the card reads the
pointers before displaying the next frame, so there can be no
tearing, even if the driver loses the CPU for half a frame right
after the retrace sync.

Anyway, this is the… uhm, I’ve lost count! I feel like a broken
record… :slight_smile:

Can we put this "why vsync in Linux just makes the tearing worse"
story in some FAQ somewhere?

BTW, anyone who’s more up to date with XFree86 than I am ATM; why
can’t DRI use DGA internally for fullscreen modes? Seems like the
code to set up actual full screen modes (as opposed to changing the
resolution of the desktop) is in place, but it’s not accessible when
it’s really needed.

//David Olofson - Programmer, Composer, Open Source Advocate

.- Audiality -----------------------------------------------.
| Free/Open Source audio engine for games and multimedia. |
| MIDI, modular synthesis, real time effects, scripting,… |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Thursday 09 October 2003 01.01, MC wrote:

Darn,

This vertical synk thing dosn’t seem to work at all, I still
experience a great amount of tearing in my game. Under windows, I
don’t have this problem. Is it linux speciffic, is v-syncing not
supported?

Darn,

This vertical synk thing dosn’t seem to work at all, I still experience
a great amount of tearing in my game. Under windows, I don’t have this
problem. Is it linux speciffic, is v-syncing not supported?

The environment variable is Linux specific. Under windows there’s a
control panel (in the advanced section of the display control panel,
I think) which lets you enable vsync for NVidia cards. Be sure to
modify the OpenGL section, not the Direct3D section.

See ya,
-Sam Lantinga, Software Engineer, Blizzard Entertainment

The way to do this in Windows is the wglSwapIntervalEXT extension.

Remember, the idea is to change it within the application, not to tell
the user to change it in a way that’s different for every card and
sometimes for different driver versions of the same card.On Thu, Oct 09, 2003 at 09:20:22AM -0700, Sam Lantinga wrote:

The environment variable is Linux specific. Under windows there’s a
control panel (in the advanced section of the display control panel,
I think) which lets you enable vsync for NVidia cards. Be sure to
modify the OpenGL section, not the Direct3D section.


Glenn Maynard

MC wrote:

Darn,

This vertical synk thing dosn’t seem to work at all, I still experience
a great amount of tearing in my game. Under windows, I don’t have this
problem. Is it linux speciffic, is v-syncing not supported?

-Mike

Gidday Mike,

For me, at least, vsync works when I’m (properly) using a hardware
surface and double bufferring.

I verified this by downloading plasma.tgz from
www.libsdl.org/projects/plasma and running it with:
./plasma -fullscreen
This produced a 320x200 animated plasma cloud, but with more tears than
the last act of Romeo & Juliet.

I then ran the same code with hardware surfaces enabled (to do this, I
needed to be root, and switch from x11 rendering to dga):

In bash:
$ su -

export SDL_VIDEODRIVER=dga

./plasma -fullscreen -flip -hw

This resulted in a much more beautiful rendition of the same plasma
effect, with no visible tearing.

As David Olofson has pointed out, this is fully dependent on the X
driver installed, and how they implement flipping. My setup is an
nVidia card, running the commercial driver (as opposed to ‘nv’), so I
don’t know how this goes on other cards. UPDATE: I just tested it
successfully on a 3DFX Voodoo3 running the tdfx driver.

Of course, since this method requires root access I realise it’s
essentially useless for developing production-quality software, but
perhaps useful as a proof-of-concept.

Maybe one day DGA won’t require root access to work. I’m not sure when
that will be…

best regards,
Greg Trounson