deconstruct the Renderer and the Window


question about the framework using opengl renderer.
do the renderer class have information about the Window(Win32Window, QMainWindow for example), using maybe pointer to it, to perform the actions like:
SwapBuffer(), Resize().

Actually, what i want is a clear opengl renderer, which can be reused in the Qt window framework with the QGLWidget class or other window framework. but if the renderer need to have a pointer to that window, then it seems … not so loosely couple.

Any information appreciated, thank you in advance.

Is this any help?

Typically in most implementations OpenGL has a view which resides inside another window. Any clear functions you do in OpenGL apply to it’s view only, and when you resize the window containing it etc. you need to tell OpenGL to resize it’s window.

If you take a look at a HelloWorld GLUT example you can see this control structure and interface between windowing systems quite clearly in the various functions. In my experience almost all windowed solutions work basically the same way.

thank you scratt.

actually, what the “view” means? is it somewhat like the QGLWidget?
It encapsulate most of the opengl commands, does it can be seen as the “view” resides inside the QMainWindow/QApplication, and it can be seen as the opengl renderer?

This will probably describe it conceptually better than I can:


thank you again:-)
it has more details in chapter2 of [Beginning Opengl game programming].

another question:
what is the relation between GDI and device context and render context?

ok, i got some info:

Device Contexts:
a windows data structure containing information about the drawing attributes of a device

  • Each window has a device context to receive the graphics output

  • Device contexts allow device-independent drawing in Windows

  • Can be used to draw to the screen, to the printer, or to a metafile

    graphics output --> DC --> device-independent drawing
    || hRC = wglCreateContext(hDC);
    || OpenGL use this rendering context to draw to the DC.
    | GDI calls.

The DC is used to create an OpenGL rendering context, This rendering context is used by OpenGL to draw to the DC and ultimately the device surface.

GDI is the original Windows 2D graphics interface.
All GDI calls pass through a DC

  • All GDI functions include the device context as the first parameter. the dc must be specified in the GDI call, while the rc is implicit in an OpenGL call.
  • GDI functions cannot be used when the window is enabled for OpenGL double buffering.