Displaying in multiple windows

I have a project that allows the user to build a scene which is displayed in Open GL. When the user adds a new models to the scene I have created a file browser that shows a thumbnail in GL as the user searches the models. The problem I am having is that once I return from the file browser the main screen turns black and nothing is displayed and it never comes back.

I have a base class call GLWindow for creating controlling the window. Both the main view and the thumbnail instatiate their own instance. This initialization is the following:

 pDC = new CClientDC (pWnd);
 hDC = pDC->GetSafeHdc();
 set up the pixel format
 hRC = wglCreateContext(hDC);

My destructor is:

 wglMakeCurrent (hDC, NULL);
 wglDeleteContext (hRC);
 delete pDC

Rendering in both windows uses something similar to:

 wglMakeCurrent (hDC, hRC);
 render scene
 SwapBuffers (hDC);
 glFlush();

Can anybody tell me what I am doing wrong? Am I missing a call, or doing something out of order.

Thank you.

http://www.opengl.org/resources/faq/technical/mswindows.htm

There’s a MFC section amidships with a FAQ and sample code.

Thank you, modus. I’ll take a look.

Sorry, but that link above didn’t seem to help much.

One difference I notice between what I am doing and the examples is that they always lay out the windows side-by-side and they are always the same size. In my application I have a CFileDialog extension dialog with an OpenGL preview screen. Since this is in a dialog it sits on top of the main display and also is a different size.

Since I am dealing with two windows of different sizes that are overlapped, is there anything different that I need to do? Do I need to redefine the viewport and perspective each time before rendering or is that saved in the rendering context? I have tried doing the wglMakeCurrent function before each rendering but that doesn’t seem to solve the problem. Thank you.

I finally got it to work. Thank you. You have to make sure and save and restore the rendering context in ALL functions that call OpenGL, including resize, etc.

I wouldn’t think it would be necessary to save and restore rendering contexts, so long as you set the context every time you’re going to use it.

A dusty old book I’ve got and one that’s mentioned in the FAQ is Ron Fosner’s OpenGL Programming for NT. It’s going on 10 years old now, but the GL stuff still seems on the mark, and I’ll bet you can grab a copy from a thrift shop for next to nothing.

Hope it helps.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.