PDA

View Full Version : Rendering to multiple HWNDs



Dark
08-05-2002, 11:33 AM
I am currently working on a small project and I need to render to 2 different HWNDs. I have a PANEL which will display a small rendering of the currently selected unit and I have a SCROLLBOX which will display the map (note that it is a WIN32 Level Editor for a game I am working on). Now I need to render that correctly... the problem is however that if I set the HWND to the main form... the SwapBuffers function will fill the whole form with the backbuffer color (glScissor doesn't work on that function). If I set the HWND to the Panel... I can draw only on the panel and not on the SCROLLBOX. I think I can get it working by creating 2 rendering contexts and using glShareList (provided that it actually shares textures) but I think there must be a better way. When I use the wglMakeCurrent(hDC, hRC) for the appropriate hDC it failed... I fixed that by setting the correct pixel format for the hDC.. however.. I still do not see anything where it is supposed to be...

If you know how to do it... please please please help me... it is driving me crazy!

Thank you in advance.

Dark

knackered
08-05-2002, 12:45 PM
First of all, you're on the right track with using wglMakeCurrent(hDC, hRC) to reuse your render context with different dc's. But, I think before you can make it current to another context, you must release it from the old one first...do this kind of thing:-

wglMakeCurrent(hDC1, hRC);
glViewport(x1,y1,w1,h1);
glScissor(x1,y1,w1,h1);
glFrustum(....);
drawstuff();
wglMakeCurrent(hDC1, NULL);

wglMakeCurrent(hDC2, hRC);
glViewport(x2,y2,w2,h2);
glScissor(x2,y2,w2,h2);
glFrustum(....);
drawsomeotherstuff();
wglMakeCurrent(hDC2, NULL);



[This message has been edited by knackered (edited 08-05-2002).]

Dark
08-05-2002, 01:45 PM
Well... I just tested that... doesn't work... do you have any other suggestions?

(thanks for your reply)

knackered
08-05-2002, 01:59 PM
Care to elaborate on "doesn't work"?
Believe me, it works. You must have made a mistake somewhere else in your code.
On creating your render context, you must first set the dc's pixel format, then create the render context from any of the dc's you've set the pixel format of.
I'm too tired to carry on....look, just post your code (the important stuff - ie. every single pixelformat/wgl/gl call, telling us where you're calling them from).

Dark
08-05-2002, 02:14 PM
Oh yeah... it works... I made a very very silly error... my CRenderSystem class had a SwapBuffers function which used the hDC managed by the class... after I used the pure SwapBuffers function it worked...

You set me on the right track. Thank you very much!

knackered
08-06-2002, 01:43 AM
Praise the Lord!

V-man
08-06-2002, 03:53 PM
<nitpick> that should be wglMakeCurrent(NULL, NULL);
for uncurrenting the RC </nitpick>

V-man

castano
08-06-2002, 07:02 PM
not really, when the hglrc is NULL, the first parameter is ignored.

knackered
08-06-2002, 11:38 PM
Yes, because only one RC can be current per thread.
But specifying the DC is far more readable when you're dealing with multiple device contexts.