View Full Version : Multiple view problem

11-20-2002, 12:59 AM
I have created 4 MDI child windows with it's own DC and RC.

But when I render my scene it only draws to the last window created.

My render function looks something like this:
for( int k=0; k<4; k++)

wglMakeCurrent(glWindow[k].dc, glWindow[k].hRC);

glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //-- Clear screen and depth buffer

SwapBuffers(glWindow[k].dc); // Swap Buffers (Double Buffering)

11-20-2002, 01:32 AM
Try doing this after your swapbuffer call:

wglMakeCurrent(glWindow[k].dc, NULL);

BTW, where is this loop running from? Is it in a thread of its own?

11-20-2002, 01:53 AM
No good MDI programming style, I would say.
Normally each MDI child window needs to handle WM_PAINT messages which itself needs to be implemented in the message handler procedure associated with the MDI child window class. Depending on the MDI child document type those procedures can be very different, it's all your responsibility, for your case it should be the same handler.
A redraw can then be enforced by sending a WM_PAINT message to each MDI child, which needs to react accordingly by repainting itself in the WM_PAINT handler.

This can be achieved by sending a WM_PAINT message to each MDI child.
Something like this will force the repaint on the complete client window area
for (k = 0; k < 4; k++) InvalidateRect(glWindow[k].hwnd, NULL, FALSE);

The MDI child message handler needs to do something like this (Just written from memory, not fail safe, not compiled, you'll get the idea. http://www.opengl.org/discussion_boards/ubb/smile.gif)

LRESULT CALLBACK MDIChildWndProc(HWND hwnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
switch (uMessage)
// get hdc, set pixelformat, create rendercontext, make current, don't release hdc!
return 0; // Continue window creation. (Otherwise return -1 to destroy.)
// cleanup opengl objects, release rendercontext, release hdc.
wglMakeCurrent(hdc, NULL);
ReleaseDC(hWnd, hdc);
break; // DefMDIChildProc() handles the rest.

case WM_PAINT:
glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //-- Clear screen and depth buffer
ValidateRect(hWnd, NULL);
return 0;

return (DefMDIChildProc(hwnd, uMessage, wParam, lParam));

11-20-2002, 02:27 AM
Hmm... still it's only the last MDI window created that renders the scene. http://www.opengl.org/discussion_boards/ubb/frown.gif

Is there something wrong in the way I create my MDI windows?

John Jenkins
11-20-2002, 10:26 AM
Here is how I did it.

Sub Main()
Dim Done As Boolean
Dim frm As Form
Done = False
fullscreen = False
' Create Our OpenGL Window
Set frm = New Form1
CreateGLWindow frm, 640, 480, 16, fullscreen
CreateGLWindow Form2, 640, 480, 16, fullscreen
wglMakeCurrent frm.hDC, hrc
Do While Not Done
SwapBuffers (frm.hDC)
wglMakeCurrent Form2.hDC, hrc
glClearColor 1, 1, 1, 1
SwapBuffers (Form2.hDC)
glClearColor 0, 0, 0, 1
wglMakeCurrent frm.hDC, hrc
End Sub

11-21-2002, 01:09 AM
>>Is there something wrong in the way I create my MDI windows?<<

Strip down your app to the absolute minimum amount of code which shows the error and put it somewhere to look at and we'll see. http://www.opengl.org/discussion_boards/ubb/wink.gif

11-25-2002, 03:32 AM
Ok, I thing I solved some of the problem.

I initialized some of the ogl params in the wrong order. Didn't know that I needed to set all the gl params for each window.

Now there is another problem.
When I set the new DC ( wglMakeCurrent ) all textures loaded seems to be lost.

Do I really need to reload all textures when I change DC?

Since I have 4 viewports I have to reload all textures four times every frame http://www.opengl.org/discussion_boards/ubb/smile.gif

Any idea what is wrong here?

11-25-2002, 04:42 AM
Originally posted by qiz:
Ok, I thing I solved some of the problem.

Any idea what is wrong here?

try using wglShareLists(glDC1,glDC2);

11-25-2002, 08:43 AM
Thank you AdrianD.
That solved it all. =)

Thank you all for helpfull replys.