multiple rendering contexts

Started by
3 comments, last by soconne 19 years, 3 months ago
I have two windows I would like to render to, each with their own HDC. I tried switching to the second window during rendering doing: wglMakeCurrent(hDCSecondWindow, hRC); where hRC is the only one created for both windows, but was created when the first hDC was made. I do this but nothing shows up in the second window, and rendering in the first window stops. How can I use the same hRC for both windows, but have rendering switch between the two ?
Author Freeworld3Dhttp://www.freeworld3d.org
Advertisement
Probably you have to create a separate OpenGL rendering context for every window
I've read before that you can have a single rendering context, but multiple HDCs. Anybody know how to do this correctly ?
Author Freeworld3Dhttp://www.freeworld3d.org
Well I created and initialized 2 HDCs and 2 HGLRCs, but when I call wglMakeCurrent , my app crashes.

Here's the code

HDC MeshPreviewhDC, ViewporthDC;HGLRC MeshPreviewhRC, ViewporthRC;void Init(){        MeshPreviewhDC = GetDC(PanelMeshPreview->Handle);        PIXELFORMATDESCRIPTOR pfd = {    	        sizeof(PIXELFORMATDESCRIPTOR),                1,                PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,                PFD_TYPE_RGBA,                32,                0,0,0,0,0,0,                0,0,                0,0,0,0,0,                32,                0,                0,                PFD_MAIN_PLANE,                0,                0,0,        };        int PixelFormat = ChoosePixelFormat(MeshPreviewhDC, &pfd);        SetPixelFormat(MeshPreviewhDC, PixelFormat, &pfd);        MeshPreviewhRC = wglCreateContext(MeshPreviewhDC);        if(MeshPreviewhRC == NULL)    	        ShowMessage("hRC == NULL");        if(wglMakeCurrent(MeshPreviewhDC, MeshPreviewhRC) == false)    	        ShowMessage("MakeCurrent failed.");        ViewporthDC = GetDC(Viewport->Handle);        PIXELFORMATDESCRIPTOR pfd = {    	        sizeof(PIXELFORMATDESCRIPTOR),                1,                PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER,                PFD_TYPE_RGBA,                32,                0,0,0,0,0,0,                0,0,                0,0,0,0,0,                32,                0,                0,                PFD_MAIN_PLANE,                0,                0,0,        };        int PixelFormat = ChoosePixelFormat(ViewporthDC, &pfd);        SetPixelFormat(ViewporthDC, PixelFormat, &pfd);        ViewporthRC = wglCreateContext(ViewporthDC);        if(MeshPreviewhRC == NULL)    	        ShowMessage("hRC == NULL");        if(wglMakeCurrent(ViewporthDC, ViewporthRC) == false)    	        ShowMessage("MakeCurrent failed.");}void Render(){        wglMakeCurrent(ViewporthDC, ViewportRC);        // render stuff        wglMakeCurrent(MeshPreviewhDC, ViewportRC);        // render stuff}The error I get is an error with atioglxx.dll
Author Freeworld3Dhttp://www.freeworld3d.org
I figured out why it was crashing.

In my call to SwapBuffers I was passing the Viewport's hDC, instead of changing it to the second hDC.

But it is possible to use a single HGLRC and two HDCs.
Author Freeworld3Dhttp://www.freeworld3d.org

This topic is closed to new replies.

Advertisement