Question about DCs and OpenGL

So I'm making a Map Maker using Win32 and WGL for OpenGL and I have a few questions. One thing I noticed is that as soon as I got the OpenGL context created and call glClear(), it clears the whole screen. I think this is because I have the DC of the main hWnd. Does every control have it's own DC? Can I just create a blank control and attach OpenGL to that hWnd and will it only clear that control? Can someone just explain how a DC works?
One thing I noticed is that as soon as I got the OpenGL context created and call glClear(), it clears the whole screen. I think this is because I have the DC of the main hWnd.

It shouldn't clear the whole screen unless you called GetDC(0) (which gets the device context of the screen). If you got the DC of the window, then glClear() should clear the client area of the window. Did you call wglMakeCurrent after you got the DC/RC of your main window?

Does every control have it's own DC?

Not quite. Drawing to the DC of a child control will draw to the DC of that control's parent.

Can I just create a blank control and attach OpenGL to that hWnd and will it only clear that control?

I haven't tried it but that sounds plausible. You can probably do anything if you respond to that control's WM_PAINT message.

Can someone just explain how a DC works?

Essentially, a DC stores all the graphics-related stuff for a particular control. A DC is used internally by the controls and when we GetDC, it's usually only to pass it around without modifying it.

MSDN wrote:
A device context is a structure that defines a set of graphic objects and their associated attributes, as well as the graphic modes that affect output. The graphic objects include a pen for line drawing, a brush for painting and filling, a bitmap for copying or scrolling parts of the screen, a palette for defining the set of available colors, a region for clipping and other operations, and a path for painting and drawing operations.


http://msdn.microsoft.com/en-us/library/dd183553(v=VS.85).aspx
Topic archived. No new replies allowed.