View Full Version : Rendering to multiple HWNDs

08-05-2002, 10: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.


08-05-2002, 11:45 AM
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);
wglMakeCurrent(hDC1, NULL);

wglMakeCurrent(hDC2, hRC);
wglMakeCurrent(hDC2, NULL);

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

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

(thanks for your reply)

08-05-2002, 12: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).

08-05-2002, 01: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!

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

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


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

08-06-2002, 10: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.