PDA

View Full Version : OpenGL in multiple windows



GeoNova
09-20-2003, 04:32 PM
My project is to write two ocx's with OpenGL displaying 3D graphics. In both of them, objects are drawn in 3D environment with textures. My problem is that every time when I change the size of one ocx, the view on another ocx is squished in X direction. Another problem is that when I change the textures (add/delete) in one ocx, the texture on the other one get damaged as well.

Thanks a lot for the help!

Dave Milici
09-22-2003, 11:18 AM
This sounds like a common problem I've seen in MFC-based apps when multiple OGL windows are opened. The key is to create and maintain *separate* rendering contexts and GL states for each open window instance.

GeoNova
09-25-2003, 06:30 PM
Originally posted by Dave Milici:
This sounds like a common problem I've seen in MFC-based apps when multiple OGL windows are opened. The key is to create and maintain *separate* rendering contexts and GL states for each open window instance.

Thanks for the reply!

Could you please describe it more detail about how to "create and maintain *separate* rendering contexts and GL states for each open window instance"?

For my particular example, I have two window instance drawing with OpenGL, and both use 2D textures. Each one works perfectly alone. But if both of the windows are opened, the texture name in one window will be set with wrong name. For example, I have 17 textures in one window, and 1 texture in another window. The window which has 1 texture will have a texture name as "18". Since I need to delete the 17th texture in the first window and re-generate it with different image, the 17th texture's name becomes "1", so that the real texture "1" got damaged.

I tried avoid to delete and re-generate the 17th texture, but it seems not work either.

http://www.opengl.org/discussion_boards/ubb/frown.gif

GeLeTo
09-26-2003, 06:53 AM
from the OpenGL Gamedev FAQ:
13.05: Why doesn't rendering to multiple windows under Win32 (or MFC) work.

You need to make sure CS_OWNDC is part of the window class.

For MFC it is often temping to add CS_OWNDC to the cs.style parameter, but that is _not_ the correct way to do it. The following link shows an example of doing it correctly:
http://www.codeguru.com/doc_view/custom_window_class.shtml


[This message has been edited by GeLeTo (edited 09-26-2003).]

GeoNova
09-26-2003, 08:02 AM
I have found the problem! It was my fault. I didn't use the function wglMakeCurrent() correctly.

In my case, in both classes, I have several OpenGL function calls in different class methods. When both of the windows are running, those methods are called interchangeably. I just realized that I have to add this "wglMakeCurrent" call in every class method if there is any OpenGL function call inside the method. Otherwise, the OpenGL function calls in one class method may actually drawing contents on the DC of the other class.