Multiple view problem

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
	qRenderer.Add(&scene.objectList[0]);
	qRenderer.Render(&Cam);

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

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?

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. )

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

  case WM_PAINT:
    glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); //-- Clear screen and depth buffer
    qRenderer.Add(&scene.objectList[0]);
    qRenderer.Render(&Cam);
    ValidateRect(hWnd, NULL);
    return 0;
}

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

}

Hmm… still it’s only the last MDI window created that renders the scene.

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

Here is how I did it.

Sub Main()
Dim Done As Boolean
Dim frm As Form
Form2.Show
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
DrawGLScene
SwapBuffers (frm.hDC)
wglMakeCurrent Form2.hDC, hrc
glClearColor 1, 1, 1, 1
DrawGLScene2
SwapBuffers (Form2.hDC)
DoEvents
glClearColor 0, 0, 0, 1
wglMakeCurrent frm.hDC, hrc
Loop
End Sub

>>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.

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

Any idea what is wrong here?

Originally posted by qiz:
[b]Ok, I thing I solved some of the problem.

Any idea what is wrong here?[/b]

try using wglShareLists(glDC1,glDC2);

Thank you AdrianD.
That solved it all. =)

Thank you all for helpfull replys.