about page flipping

hello…

I have two sources…
one is left eye images… another is right eye images…
The Display’s refresh rate is 120 Hz…
I want to draw Left and Right eye images with 120 HZ to realize page flipping …

But I dont’t know how to get the 120HZ signal to
accurately draw Left or Right eye images on display…

Does anyone know how to realize page flipping?
Thanks!!

You need to enable the option vsync (vertical synchonization) when you create your OpenGL context. This will synchronize updates with the updating of the screen. I’m not sure how you do that, but try googling around for vsync and your environment.

If you are using SDL, just put SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, 1); before your SDL_SetVideoMode(); call and every other frame draw from the left eye and every other from the right eye.

This, of course, doesn’t take into account that you are probably going to use some kind of 3D glasses with this thing. So it might draw the frames in the wrong order or not synchronized with the glasses at all, but you just have to work that out by yourself, if there is an SDK for the glasses it should give helpful information.

Personally I don’t like stereo 3D, it just doesn’t work well enough - the effect feels like nothing after a few minutes. We need real 3D screens.

First you need to obtain a sterio frame buffer.
In windows you add the PFD_STERIO flag to the existing ones set in dwFlags of the PixelFormatDescriptor when you call ChoosePixelFormat.
Then (assuming PFD_DOUBLEBUFFER was also set) you just select the left eye view with glDrawBuffer(GL_LEFT_BACK), draw your image to that framebuffer, call glDrawBuffer(GL_RIGHT_BACK), draw the right eye image, then finally call SwapBuffers.

When sterio mode is enabled, OpenGL automatically switches between the left and right eye views at the monitor refresh rate.
SwapBuffers works at half the refresh rate in this mode, 60Hz in your case, swapping GL_LEFT_BACK with GL_LEFT_FRONT and GL_RIGHT_BACK with GL_RIGHT_FRONT at the same time.

Hi!

As far as I know, PFD_STEREO will only work for quad-buffered cards (maybe you can experiment with emulation using RivaTuner, I read some threads about it, however never tried).

For enabling/disabling vsync you can use the wglSwapIntervalEXT function in Windows (http://www.opengl.org/registry/specs/EXT/wgl_swap_control.txt), but check the driver settings, becouse it could be forced to turn on/off.

This, of course, doesn’t take into account that you are probably going to use some kind of 3D glasses with this thing. So it might draw the frames in the wrong order or not synchronized with the glasses at all, but you just have to work that out by yourself, if there is an SDK for the glasses it should give helpful information.

Yes, there’s some problem with using only vsync. I don’t know how proper synchronization could be achieved when frame rate occasionally drops under monitor frequency. Its especially hard to draw each frame in 8 msec in your case (120 Hz). If you have nvidia card, you can use NVAPI, it has a function NvAPI_GetVBlankCounter (don’t know if ATI’s ADL_SDK has similiar function), and using this information you can draw left or right image for the even/odd number returned by this function. But this function call could take a lot of time also. And don’t know if any other way to counting vblanks exists, maybe you could experiment with simple time measuring.

Maybe some experienced programmer could imagine how nvidia implemented stereo for their 3D vision kits, and why it’s not implemented for OpenGL.

(sorry in advance for the somewhat rantish post)

Haha, it has more to do with business than programmation. They obviously want to keep professional customers with the Quadro line, and not the cheaper Geforce line.
Which is stupid for development of 3d stereo in general.
http://forums.nvidia.com/index.php?showtopic=104468&st=0
At least the 3D vision kit seems now to be compatible with Quadro cards :
http://forums.nvidia.com/index.php?showtopic=95729&view=getlastpost

And the idea of doing the stereo work in the 3D kit instead of the game seem nice for lazy gamedevs. Then nvidia give recommendations to devs to better take advantage of stereo… Exposing the GL quad buffered stereo directly would be better than any guesswork by the NV kit and its profiles (hud, crosshair, labels, not to mention image-space effects and deferred rendering stuff, all these have problems).
And Doom 3 would instantly look twice better on my computer as it already supports quad buffered stereo …

As an aside note on active 3D stereo, I find it great for slow or mostly static content. Fast action feels wrong due to the delay between eyes. Anaglyph corrupts the colors, but at least fast action is correct :slight_smile:

Hello…

Last week I posted an article about “age flipping”
Thanks for your reply and suggested me to use NVAPI… ^0^
appreciation… laugh

I tried to use this instruction to get the V-sync signal
NvAPI_GetVBlankCounter ( NvDisplayHandle hNvDisplay,
NvU32 * pCounter )
It could run…
pCounter is a number,but I still have no idea how to apply it… frown

I search the sample code with google…
The information is few…

can you tell me how to use this to be the display refresh rate
trigger?? Thanks!!

Hi,

I use this with the following scenario:


at initialization:
wglSwapIntervalEXT(1);


in every frame:

if ((frame_counter % 2) == 0)
{
    // render left eye to left_tex
    ...
}
else
{
    // render right eye to right_tex
    ...
}

NvAPI_GetVBlankCounter(hDisplay, &vblank_count);

left = (vblank_count % 2) == 0;

if (left)
{
    tex = left_tex;
}
else
{
   tex = right_tex;
}

draw fullscreen quad with tex to the default framebuffer

SwapBuffers(hdc);

SwapBuffers will empty the OpenGL command buffer, waits for a vertical retrace, and then swaps the back and front buffers. So, according to how many GL commands are in the buffer, this could take a lot of time: 1, 2 or more vblanks. Thus it’s not guaranteed that rendering is in synch, and artifacts may occur: one image displayed for 2 or more vblanks, and then left and right images may be swapped for subsequent frames. This could be corrected by the GetVBlankCounter. But of course some frames will surely wrong.
The whole thing works only if the frame rate mostly stable and can produce the frames in the speed of monitor frequency. When occasionally doesn’t, then swapping of left and right eyes may happen for some frames. I don’t know if any better method exists for non-quadbuffered cards, but I will be very happy if someone could show one.

Maybe other techniques could be used for counting vblanks. The problem with GetVBlankCounter is that it could take as long as 1-3 ms in my case. But I don’t know any other method.

Hello~~!! thekend ~~!
Thanks for your suggestion… ^0^
It could run successfully…
But there’s still another problem …
vblank_count is not stable …

Sometime I got the same value after calculation (vblank_count % 2)
for example :

vblank_count % 2 = 0
vblank_count % 2 = 1
vblank_count % 2 = 0
vblank_count % 2 = 1
vblank_count % 2 = 1 <–wrong!!
vblank_count % 2 = 0

and the flicker effect will be happened…
How can I solve this problem that I can show L & R Image or Video
stably…
Thanks~~!! ^^

Maybe that’s due to your app dropping frames because
your render loop took longer than 1/60s? Print out
vblank_count and see if the values are continuous,
like 1,2,3,4,5 and not something like 1,2,3,5,6.

can you prints all the codes?
I have the same question, but I don’t know how to solve it.