Advertisement

opengl mdi

Started by June 12, 2005 02:04 PM
7 comments, last by llvllatrix 19 years, 8 months ago
Is there a way to have a multiple document interface (e.g. window in windows), where one of the windows is an opengl window, and the others hold buttons etc. The reason for this is that I am developing my own tools for my next game. Any help is greatly apreciated, thank you.
Yup,

You should be able to adapt the first tutorial to work with mfc. You're going to have to do a bit of context management if you have multiple opengl windows but with a bit of planning, this shouldnt be too hard. If you set things up correctly, you should be able to put a 3d gl context on pretty much any window. Just make sure you have a copy of the red book on hand and things should go smoothly. You are also going to have to tweak the mfc drawing properties to get smooth frame rate, but a quick google should resolve these problems.

Cheers,
- llvllatrix
Advertisement
I have got the opengl to work with mfc before, and I have made an mdi before (using this method http://www.functionx.com/vcnet/Lesson07.htm)

The problem I have is in combining them to get a sub window with opengl, and a second sub window with buttons.

Double clicking on the sub window brings up a .h for that window, but I am stuck as what to do next.
Alternatively is there a way of having the window at a set size, but drawing the opengl to a smaller set size with space around it. Then have any buttons excetera in this space.
Quote:

Alternatively is there a way of having the window at a set size, but drawing the opengl to a smaller set size with space around it. Then have any buttons excetera in this space.


Yes, you should be able to draw opengl within a picture box provided you can get a rendering context off it.

Cheers,
- llvllatrix
How do I get the rendering context off it, and how do I get opengl to render to it?
Advertisement
If I recall correctly, OpenGL needs a device context (DC) from windows to do the rendering. You should be able to get that off of any class derived from the wnd class. Once you have that you do a bit of setup to generate a render context (RC). Then its just a matter of switching to the appropriate RC before you start calling GL commands.

Again, you're going to have to do a bit of research on grabbing a DC from an instance of a class in the MDI frame. I'm a bit busy right now, but I'll see if I can pull up some MFC links when I get home.

Cheers,
- llvllatrix
thank you
Just for the record, I try to avoid MFC and win32 whenever possible...that said, i'm not particularly good at this stuff, but i'll try to make it as accessible to as many people as possible...

Resources:
Here's a good source of tutorials on MFC and many other windows based programming tools:
http://www.codetools.com/
What you're probably looking for is something to the effect of a picture control:
http://www.functionx.com/visualc/controls/picture.htm
As alawys, make sure you have a copy of the red book on hand:
http://www.gamedev.net/reference/count.asp?LinkID=993

How GL works with Windows:
In any windows program, you can have multiple subwindows (ie dialog boxes, tabs ect) each drawing their own content. The problem is, how does opengl know which window to send the current gl commands to? For that matter how does MFC do it? Each window in MFC has a "handle to a device context" or HDC. A HDC means that somewhere tucked inside windows, an area of the screen (ie the hardware) is reserved for the control being drawn in the area. For example, if you had a program that occupied the bottom right quarter of your screen, then windows would reserve it a that area of your monitor to draw to and no where else. Your program can access this area of the screen by the "handle" which basically means a shortcut to this area of the screen.

OpenGL can also access the HDC. However we still have the problem of sending gl commands to the right window. HRCs to the rescue. The HRC is GL's own version of an HDC. You associate a HRC to an HDC. Then, when you want to draw to a HRC, you just bind it like you would a texture using:

wglMakeCurrent(hDC,hRC)

In Nehe's tutorials we have always had 1 hDC and 1 hRC, so we've only ever had to call this function once. The same is true if you're only going to use 1 gl screen in your context; you only have to call this function once because you assume that all of the gl commands will go to that one window. If you have more than one however, you need to call this function before issuing gl commands.

So to sum it up, to make opengl go on a window we need an hDC. With an hDC we can make a hRC, so that we can route gl commands. So really, all we need to make a gl window is an hDC and fortunately almost all MFC classes that have visual components come fully equipped with hDCs that are easy to get:

HDC hdc = GetDC(c_wnd_class.m_hWnd);

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/devcons_4esj.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_mfc_cwnd.3a3a.m_hwnd.asp

Hope this helps,
- llvllatrix

This topic is closed to new replies.

Advertisement