OpenGL in multiple Windows

im writing a simple 3d modeller type program.

for each viewport i have to

initialise openGL
Draw the object
Shutdown opengl

i put this code under wm_paint for each viewport (each viewport is a window in its own right) however this method is making the appliction very slow, not to mention the nasty flickering thats going on because i cant swapbuffers, as i release the device context in the shutdown.

i thought of using glViewport(…) but that wont let me keep a windows messaging system as easily.

Hi !

You can do doublebuffering anyway, make sure that you handle the WM_ERASEBKGND message to avoid flickering also.

Using glViewport to handle is much better, you only need one gl context, just add a few lines to add support for splitters and you will not notice any difference.

The actual switching of contexts is pretty expensive so if possible avoid it and use glViewport instead, is not very complicated to implement.

Mikael

Don’t do the initialize and shutdown in the WM_PAINT message. Do the initialize for each in something like the WM_CREATE. (If you are using MFC, the overloaded OnInitialUpdate is also a valid place to do this.)

Then in your display, just use wglMakeCurrent to make that window’s RC current before drawing.

You should also make sure you setup each of the windows to have the CS_OWNDC style. That is a parameter used in creating the window “class” so if for instance you are using MFC, you would put something like so in your PreCreateWindow()

cs.lpszClass = AfxRegisterWndClass(CS_OWNDC | whatever_else);

WndClass.style = CS_OWNDC; appears to have fixed that filickering problem. i dont understand why but it did, thanks.

now to solve the OTHER problems. :slight_smile: