2

I'm writing an application that is looking to draw basic polygons and ellipses on the Windows 7 desktop using OpenGL. According to this previous question, this is possibly by getting the window handle to the desktop, which I know how to do. Draw OpenGL on the windows desktop without a window

However, I've got two questions:

  1. Where do you actually tell OpenGL what window to draw to? I've been looking through nehe example 1, and I simply can't figure out where exactly it's passing openGL the hwnd. Do I give openGL a window handle or a device context?

  2. Is it possible to do this using PyOpenGL or Pyglet? Or would I have to write it in C, then wrap the code in ctypes?

Community
  • 1
  • 1
jmite
  • 8,171
  • 6
  • 40
  • 81

1 Answers1

2

Trying to do OpenGL on another process' window is a really, really bad idea! For OpenGL to work it needs to set the window's pixel format. However the pixel format of a window can be set only once, so doing this on a foreign window is a recipe for disaster.

The proper way to do this, but it's slow like nothing else is to use a PBuffer, which has it's own off screen HDC, render to this PBuffer and BitBlt from the PBuffer to the target window. I've never implemented this myself though, so I can't tell you how well this works first hand. But it sounds like an interesting thing to try, so maybe I'm doing that next time I boot Windows on my machine.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • Thanks! When I think about it, this is really true. Come to think of it, this wouldn't have even done what I wanted, what I want is a window that's always on top with a transparent background. – jmite Jun 29 '11 at 22:06
  • @jmite: Then you should read http://msdn.microsoft.com/en-us/library/ms997507 - layered windows don't work with OpenGL either, so the trick is again rendering in a PBuffer and BitBlt. – datenwolf Jun 29 '11 at 22:12