hDC and rDC question

This is a discussion on hDC and rDC question within the Windows Programming forums, part of the Platform Specific Boards category; I'm learning opengl and I don't quite understand what the hdc and rdc do. Here's what I believe they do. ...

  1. #1
    Registered User
    Join Date
    Dec 2006
    Posts
    51

    hDC and rDC question

    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

  2. #2
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    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 08:19 PM.

  3. #3
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,549
    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.

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    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

  5. #5
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,189
    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.
    Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.

  6. #6
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,893
    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

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21