- Adding in OpenGL support to a MFC project
What you'll need:
- Visual Studio 2005--yes, you have to have 2005 for this one because of restrictions on DIGuy
- OpenGL installed on your machine
- Optional: The classes I wrote for OpenGLMFC. If you don't have them you'll have to figure out how to call functions by themselves. This tutorial is focused on getting the project settings right.
How to do it:
1) If you don't have my class for OpenGL, I'd recommend following this tutorial:
http://www.codeguru.com/cpp/g-m/opengl/openfaq/article.php/c10975__1/Setting-Up-OpenGL-in-an-MFC-Control.htm
It is clear and does a good job of explaining step by step what to do.
2) If you do have my class, go ahead and add it to your solution.
3) Go to Project Settings>Linker>Input. Under "Addtional Dependencies," add "opengl32.lib" (and "glut32.lib" won't hurt either).
You should now get a clean compile.
4) Now to make a place for it to render and link in the correct events. I rely heavily on the tutorial listed above for this.
Go to Resource View and open up your program's dialog.
5) Open up the Toolbox (it's probably in a tab to the left side of the screen and select an Image control. Drag that onto your dialog.
6) Make sure your picture control is selected, then go to the Properties tab. Change its ID to something useful, like IDC_OPENGL.Also, set its visibility to FALSE. (Weird, I know.)
7) Now we're going to link that image control to the OpenGL class that I've written. Open up the header code for your dialog box (in my case, it is VPDialog.h). Include your OpenGL header. Declare an object of that class type. Mine is called openGL, so the code I added is:
#include "OpenGLMFC.h"
...
(inside class declaration)
OpenGLMFC openGL;8) Now, open up the cpp file corresponding to that header. Find the InitInstance() function.
Insert code to link up your image control with the OpenGL rendering:
CRect rect;
GetDlgItem(IDC_OPENGL)->GetWindowRect(rect);
ScreenToClient(rect);
//create the OpenGL renderer
openGL.oglCreate(rect, this);
//set the timer for rerendering
openGL.m_unpTimer = openGL.SetTimer(1,1,0);
8) You're all done integrating! Now you just need to set up your callback function for rendering, which you can either do within the OpenGL class or assign a function to the callback member of that OpenGL class.




No comments:
Post a Comment