why SwapBuffers doesn't work?

Can anyone help me?

The animations are flickering although I use SwapBuffers.
ex: SwapBuffers(pDC->GetSafeHdc());
I don’t get the correct HDC or what?

Are you using double buffer? Are you calling SwapBuffers more than once per frame?

I “enabled” PFD_DOUBLEBUFFER and I use SwapBuffers every time after I create the current scene.

Have you checked your code to make sure that SwapBuffers is only being called once. I accidentally had 2 calls one time time and others have also, which results in flickering. Also, check to see if you have vsync turned off. If so, turn vsync on and see how it looks. Maybe it is just tearing. Other than that, you would have to show some code, or give much more detail. Is the entire screen flickering? Parts of the screen? Just certain objects?

I call SwapBuffers only once per scene and the flickering affects all the rendered objects. About vsync don’t know much, is part of glut? (I only use the VC’s gl.h && MFC)
Actually SwapBuffers does nothing in my case (if I take it out the result is exactly the same - flickering).

Is the flickering the exact same with or without the SwapBuffers? Without swapping the buffers, there shouldn’t be any animation at all, because you would be rendering to the back buffer and the front buffer would just be blank. Did you check to verify that the PIXELFORMATDESCRIPTOR you requested is the same as what was set with SetPixelFormat? What values did you et PIXELFORMATDESCRIPTOR to?

Could it be that you:

glDrawBuffer( GL_FRONT )


It sounds like you are using MFC. Have you overloaded OnEraseBkgnd and made it return TRUE? If that’s not done, Windows will erase the window itself to whatever color was used for the background brush. Returning TRUE tells MFC that you handle that yourself.

Still doesn’t explain why you get the same results with or w/o SwapBuffers. But it still might be something to check.

Probably the Window background color
must be different from the OpenGL clear color. Set both to the same color and try


Thank you all for the advices !

From what I’ve seen in my code:

  • I have glDrawBuffer(GL_FRONT_AND_BACK);
  • I am setting correctly the PIXELFORMATDESCRIPTOR;

I still haven’t tried to overload the gl function, but in the days to come shall do it.
It is strange that the behaviour is the same with SwapBuffers or w/o, but at home I see no difference. Actually all my problems appear at work, where the scene flickers like hell. I heard something about some graphic cards making themselves some sort if prebuffering so it can be explained why it’s all ok at home.

Originally posted by RainMan:

  • I have glDrawBuffer(GL_FRONT_AND_BACK);

That’s your problem

Try glDrawBuffers(GL_BACK);
Or you can erase the line altogether, because GL_BACK is the default.

With GL_FRONT_AND_BACK you’re in effect disabling double buffering (well, not quite, but you lose the benefit double buffering: it avoids the flicker).

I already tried posting that a few days ago with some more information, but this board wasn’t working right, it seemed.

[This message has been edited by zeckensack (edited 05-20-2003).]