Rendering to multiple HWNDs

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

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

Well… I just tested that… doesn’t work… do you have any other suggestions?

(thanks for your reply)

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

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!

Praise the Lord!

<nitpick> that should be wglMakeCurrent(NULL, NULL);
for uncurrenting the RC </nitpick>

V-man

not really, when the hglrc is NULL, the first parameter is ignored.

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.