I'm learning opengl and I don't quite understand what the hdc and rdc do. Here's what I believe they do.
So you have multiple programs running thus multiple windows. So whatever is your main window it would set the hdc to the rdc?
Gah Im confused
I'm learning opengl and I don't quite understand what the hdc and rdc do. Here's what I believe they do.
So you have multiple programs running thus multiple windows. So whatever is your main window it would set the hdc to the rdc?
Gah Im confused
hDC has to do with the device context. I'm not quite sure why a device context is needed, but since you're drawing in a window using Win32 API, you need a device context. Try googling it.
EDIT: BTW, hDC = handle Device Context.
Last edited by scwizzo; 11-04-2007 at 09:19 PM.
It's GDI mumbo-jumbo. Pretty much a handle to the context of your application. You could see it as an image of your window, to where you need a handle for Windows to identify it. CodeProject has excellent tutorials on device context objects.
hDC == Handle to a Device Context (CDC in MFC).
rDC == Rendering Device Context (only OpenGL IIRC)
A Device Context is a structure that contains GDI objects (bitmap, pen, font, brush) used to draw to the applications screen. Calling GetDC(NULL) gets the whole screen rather than just the apps.
OpenGL uses a 'rendering' DC obtained from the apps DC using wglCreateContext(). IIRC OpenGL allows you to draw this DC (while displaying the last frame). You then call SwapBuffers() to draw from the rDC to the hDC (and so update the current screen). This can be done in WIN32 with a 'memory' DC.
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
A handle is like a pointer, except that instead of pointing to an address in memory, it points to some other object, in this case a device context. A DC is how windows decides which appliation has control of a resource that cant be controlled by more than one process simultaneously. In this case its the video display. Thats why you GetDC() and then ReleaseDC() as quickly as possible. Its like a CRITICAL_SECTION only for hardware.
A device context is just an abstraction. It's an abstract handle to a device. It doesn't define mutually exclusive access (that would be something - one app forgetting to call ReleaseDC would bring down the entire system!), it doesn't define what the device is. It provides information about the device and allows some operations being performed. It doesn't care whether this device context is a plotter, a printer (or rather, a printer driver's spool collector), a memory buffer, a screen, just a portion of a screen (e.g. a window) or some other obscure graphical display device. That's why it's an abstraction.
A rendering context is an OpenGL concept. The rendering context represents the 2d/3d hardware you interact with, including information about where on the final output device the output should appear. Thus you create rendering contexts from device contexts in Windows, because that's the easiest way for Windows to know where you're rendering to. What you get returned is a HGLRC, a handle to an OpenGL rendering context, which you can use to set one of the contexts you created as the active one. (The OpenGL system is a state machine that doesn't want a handle for every call.)
All the buzzt!
CornedBee
"There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
- Flon's Law