OpenGL and GDI problems on Vista

I’m having some problems rendering OpenGL and GDI to the same window under Vista. I don’t want to mix OpenGL/GDI rendering, I just want to be able to re-use the window for GDI rendering after I’ve done some OpenGL in it (and vice versa). A search of the web has thrown up some articles hinting that it can’t be done, but I’ve not found anything definite.

The behaviour I’m seeing is if I render to window with OpenGL, then when I do any GDI, it’s never displayed except if i increase the window size, then the GDI calls are rendered to the areas of the window that were not written to by OpenGL. (Strangely though, if I now shrink the window, render OpenGL, then expand the window, I can use GDI to update parts of the screen that I previously couldn’t. It’s only the last OpenGL render to which GDI won’t update).

This all works fine under 2000/XP, so I’m guessing the new WDDM stuff is getting in the way somehow. Does anyone know of a workaround, barring re-write the GDI part in OpenGL?

The most accurate description of why GDI works totally different under Vista is to be found here:
http://blogs.msdn.com/greg_schechter/archive/2006/05/02/588934.aspx
Summary: Do not mix GDI with a HW accelerated 3D API to the same window under Vista, it won’t present correctly.

OpenGL can only be attached to a window once in the window’s lifetime (SetPixelFormat) and there is not way to remove a pixelformat other than destroying the window.

If you work single buffered, Vista won’t show any OpenGL rendering until you send glFlush() or glFinish(). That was always the case, but with a separate compositing surface you can buffer any number of OpenGL commands.

For GDI that’d be GdiFlush().

Originally posted by MrNurse:
I’m having some problems rendering OpenGL and GDI to the same window under Vista.

This all works fine under 2000/XP, so I’m guessing the new WDDM stuff is getting in the way somehow. Does anyone know of a workaround, barring re-write the GDI part in OpenGL?

  • The first suggestion is don’t: if you only require a minimal subset of GDI, build your GDI to OpenGL translator, it will get hw accelerated (GDI is on software on Vista) and the world will be a happier place.
  • The second suggestion is compose GDI and OpenGL yourself (glReadPixels/glDrawPixels, GDI blits).

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