views:

152

answers:

1

Basically I am being called to render to an offscreen DC which is set up (I'm not sure how) to use GDI+. When I try to associate an OpenGL context with the DC, it just fails (i.e. returns zero but no error). SetPixelFormat also fails (probably because it is already set up?), again by returning zero, not an error.

Anyone know whether it is possible, given such a situation (i.e. offscreen context for a window into which someone else is using GDI+), to create an OpenGL context and use OpenGL for my own rendering? (And if it is possible, why might the wglCreateContext be failing?)

+1  A: 

This article shows you all of the steps to hook up a GDI window: http://nehe.gamedev.net/data/lessons/lesson.asp?lesson=01

Essentially, you have to:

  1. Create a window
  2. Register the window
  3. Get the device context of the window's drawing area
  4. Setup the pixel format for the device context
  5. Call wglCreateContext
  6. Call wglMakeCurrent
  7. Display the window

If you already have access to the device context, skip the first two steps.

In your case, you might see if wglMakeCurrent is all you need. Otherwise, you might want to post more details about the errors and behaviors you are experiencing.

j0rd4n
The problem is that I do already have the DC (it's an offscreen device context), refering to a window I need to draw into, but that my wglCreateContext fails with no error messages whatsoever, as does my SetPixelFormat.I can create new OpenGL windows without a problem, but it's trying to use the DC given to me by the application which is the problem...
How do you know it is failing? What kind of error or code are you getting back in return? Any strange behavior or it just isn't drawing?
j0rd4n
No error code, either from OpenGL or Windows system. I know it's not working, though, because it returns 0 instead of a valid HGLRC.