how to use both gdi and opengl

I want to know that if it possible to use both gdi and opengl when double-buffer is enabled.If possible,please tell me how to realize.Your kindly help will be highly appreciated.

You need two windows, one for gdi and one for opengl. Make the opengl window a child window to the window containing the gdi stuff to make it look and act as one.

This is what Microsoft’s MSDN says about the relevant PIXELFORMATDESCRIPTOR flag
“PFD_SUPPORT_GDI: The buffer supports GDI drawing. This flag and PFD_DOUBLEBUFFER are mutually exclusive in the current generic implementation.”

This does not mean it’s true for other implementations. Normally it’s possible to draw with GDI into the frontbuffer without problems in HW.
But GDI does not know of backbuffers!

Though I would NOT recommend it for any geometric primitives, use OpenGL to get compatibility across all implementations.

Be very careful: your application MUST manually synchronize between GDI and OpenGL. glFinish for OpenGL, I forget the right command for GDI.

  • Matt

Very true, thanks Matt.
The command is GdiFlush().

But GDI does not know of backbuffers!

Some professional 3D cards have ability to enable GDI drawing to both buffers simultaneously.
(for 3Dlabs - you can enable “Broadcast GDI to Back Buffer”)

We have the ability too, but there’s no API for it – it seems like a bad idea to expose a feature that has no API.

  • Matt

Supersampling which you are using for FSAA also has no API.
But for some reason it does not prevent you from exposing this feature.

But it’s supposed to be transparent to the app – this, an app would actually have to know about to be able to use properly.

If the ability existed, it would have to be part of the GDI API.

  • Matt

Ok, I can live without it…

Anyway, this option is very application specific, and usually everything works just fine.

But it would be nice to have this ability in GDI+ (or whatever they call it).