OpenGL SwapBuffers for Vista

I have a program using OpenGL which works fine under WinXP. But it has some problems running under Vista when I do the trimming with SwapBuffers function. Who can help me about this and tell me how to use SwapBuffers under Vista?

The part of source code as below.

[b] WaitForSingleObject( TheDisplaySemaphoreHandle, INFINITE );

US_wglMakeCurrent( theView3DPtr->View3DHdc,
theView3DPtr->View3DHglrc );

SwapBuffers( View3DHdc );

glDrawBuffer (GL_FRONT );

glDisable ( GL_DEPTH_TEST );
glDepthMask ( False );
glPointSize (5.);

myPointListPtr = thePointsListPtr;

glColor4fv (TheOpenGLRedMaterial);

//red points for user
AT_ResetObjectList ( thePointsListPtr );
while( !AT_EndOfObjectList ( thePointsListPtr ) )
myPointPtr = (RealCoordinatePtr) AT_ReadObjectAndGo(
thePointsListPtr );
glVertex3f ( myPointPtr->x, myPointPtr->y, myPointPtr->z );

//red edge for splined
AT_ResetObjectList ( myTempDisplayListPtr );
my1stPointPtr = (RealCoordinatePtr) AT_ReadObjectAndGo (
myTempDisplayListPtr );
while( !AT_EndOfObjectList ( myTempDisplayListPtr ) )
my2ndPointPtr = (RealCoordinatePtr) AT_ReadObjectAndGo (
myTempDisplayListPtr );
glVertex3f ( my1stPointPtr->x, my1stPointPtr->y,
my1stPointPtr->z );
glVertex3f ( my2ndPointPtr->x, my2ndPointPtr->y,
my2ndPointPtr->z );

glDrawBuffer (GL_BACK );
glEnable ( GL_DEPTH_TEST );
glDepthMask ( True );
glPointSize (1.);
glLineWidth( 1.0f );

if( WaitForSingleObject ( TheDisplaySemaphoreHandle, 0 ) != 0 )
US_wglMakeCurrent( NULL, NULL );

ReleaseSemaphore ( TheDisplaySemaphoreHandle, 1, NULL );

Thanks in advance.

From the GL on vista articles :

“If an application renders to the frontbuffer, remember to call glFinish or glFlush whenever it needs the contents to be made visible on the screen.”

So you would need to call glFlush(); right before glDrawBuffer (GL_BACK );

And by the way, no need to call both glFlush(); and glFinish();, like at the beginning of your code. I prefer glFlush() for performance reasons.

Anyway, it is bad practice to write directly to the front buffer. Are you sure you really need it ?

Thanks a lot.

I have changed my program according your recommendation. But it still has the same problem about SwapBuffers function. It seems like didn’t refresh the buffer and copies more than one time.

Calling SwapBuffers on windowed applications incurs two extra copies. One from the backbuffer to the composition surface, and then one from the composition surface to the final desktop.

Calling synchronization routines like glFlush, glFinish, SwapBuffers, or glReadPixels (or any command buffer submission in general) now incurs a kernel transition, so use them wisely and sparingly.

I still don’t really understand about these. Could you give me some comments about this?

It is about performance optimizations : running 3d apps on Vista is a bit slower, as verified by all 3D benchmarks and games on DirectX or OpenGL.

Don’t worry about these, you don’t have a problem with performance but with correctness.

Can you rewrite your app in a way that you only draw to backbuffer ?

These discussions can be of interest :

Thanx for your kindness. I have rewrite my app in a way that I only draw to backbuffer and modified some other parts. Now it works well.

Thanks again.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.