PDA

View Full Version : Multiple view problem



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

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

knackered
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?

Relic
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)
{
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(&amp;scene.objectList[0]);
qRenderer.Render(&amp;Cam);
ValidateRect(hWnd, NULL);
return 0;
}

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

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

Relic
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

qiz
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?

AdrianD
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);

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

Thank you all for helpfull replys.