How to wait for VSYNC ?

How can I wait for VSYNC ?

There are the DirectDraw function :

IDirectDraw2::WaitForVerticalBlank()

What is the corresponding openGL function ?

Peter

On Windows, you can use WGL_EXT_swap_control, given that your driver support that extension. Or you can look for a way to enable/disable it in some control panel for your graphics board. Other than that, it’s not possible.

Can I use the GLUT:

glutPostRedisplay() - to mark the current windows will be redisplayed
glutDisplayFunc() - for callback, if the current windows will be redispayed

to wait for VSYNC ?

Peter

GLUT does not handle vsync. Either use the extension I mention, or you won’t be able to sync your program to the monitor’s vertical retrace.

That 's not always true ! I’ve got a geforce and in the config tool there’s a list “Vertical Sync”. When I choose “On by default” (which is the default option), The code proposed by Peter does work. You simply call glutPostRedisplay at the end of your display func.
Hope that helps !

Here’s an old piece of assembly that may (or may not) still work. Check your compiler’s method for including assembly
Joe

void vsync()
{
__asm
//wait for vertical sync
{
mov dx, 3dah
WaitNotVerticalSync2:
in al, dx
test al, 08h
jz WaitNotVerticalSync2
WaitVerticalSync2:
in al, dx
test al, 08h
jz WaitVerticalSync2
}
}

Morglum, I said that in my first post aswell: “Or you can look for a way to enable/disable it in some control panel for your graphics board”

Anyways, this method has nothing to do with OpenGL itself, and there is no way to control this behaviour from the program (apart from manipulating the registry manually, but I doubt that will have an immediate effect). But you are right, his code will work if this option is set to “on by default”, but if you think about it, ANY code to display an image in OpenGL will work.

just a question:
what is the utility to wait for vsync?,
if i’m not wrong, the fps will be limited to the monitor refresh rate wich is at least 60 hz, i think that it’s a good refresh rate, maybe not far from the eye limit.
well, usefull, not usefull?

marsu

Hi JoeMac

This piece of code wait activ for VSYNC.
The PC will be blocked.

I am looking for the method to wait passive for VSYNC,
in order to use the processor time for other jobs in another threads.

Peter

Activate the driver capabilities.
When you wait until the next vsync to draw stuff, your geometry comes to late and misses it anyway. You can’t know how long it will take to render the frame…

It’s really very simple.

Call SwapBuffers. If vsync is enabled, then it will wait for a vsync, and swap the buffer at the appropriate time.

As for dynamically enabling/disabling vsync, I wouldn’t suggest doing it programmatically, unless you do it before initilizing OpenGL.

Originally posted by Bob:
Morglum, I said that in my first post aswell: “Or you can look for a way to enable/disable it in some control panel for your graphics board”

Ok excuse me, I hadn’t read this thread very carefully.

Korval… that’s my point. But you would be rendering useless frames, and I think the problem was to spend the time waiting for a refresh doing other stuff on cpu…