Anda di halaman 1dari 6

Setting up Visual Studio 2010 for your first OpenGL Project

Download the Library Files................................................................1 Option 1: Add library and header files to the VS2010 installation............2 Option 2: Saving the library and header files in your documents folder and adding them to your user or project include paths................................3 Notes.............................................................................................5 Test your installation........................................................................5 Troubleshooting...............................................................................6
These notes detail how to create and and compile your first OpenGL project for Visual Studio 2010, using the freeglut libraries and GLTools library provided with the OpenGL SuperBible. Instructions for Visual Studio 2008 can be found in the OpenGL SuperBible, 5th Edition, starting on page 49.

Download the Library Files


All of the files required can be found in the large download containing all of the SuperBible code and examples from http://www.starstonesoftware.com/OpenGL/ Extract the zip and note the location where you have saved the SB5 folder (this will be something like C:\Users\admin\Documents\SB5 ) you'll need this information later. In university this might be your home drive, e.g. H:/SB5. This download includes the freeglut library as well as the GLTools files used in examples in the book. In university, freeglut will be already installed but you will still need to add the GLTools library. Alternatively, a zip containing just the freeglut and GLTools library files will be made available at 3dgamedev.wordpress.com or directly from: http://www.box.net/shared/dc1zznhdt4 Note: Do not download and install the GLEW library this has been included into the GLTools library

Daniel Livingstone(2010) CC Attribution-Noncommercial-Share Alike 3.0 Unported

Option 1: Add library and header files to the VS2010 installation


This is probably the simplest option for installing the libraries on your home machine this requires admin permission on the computer. i. Copy all of the freeglut header files (ending in .h) to the folder: C:\Program Files\Microsoft Visual Studio 10.0\VC\include\GL\

ii. Copy all of the GLTools header files (ending in .h) to C:\Program Files\Microsoft Visual Studio 10.0\VC\include\ iii. Copy all of the freeglut and GLTools library files (ending in .lib) files to C:\Program Files\Microsoft Visual Studio 10.0\VC\lib\ iv. Even though you have copied GLTools.lib into the lib folder, you may still need to tell VS2010 to use the GLTools.lib file when compiling your projects. Open the Property Manager (you'll need an open project to do this), from the menu option View Property Manager. The left hand pane of the VS IDE will change to show the property manager. You can resize this to make it more readable. Expand the project if the full listing is not shown, then double click on one of the Microsoft.Cpp.Win32.user links to open the user properties dialog. In the Property Manager, select Linker Input, then click on the Additional Dependencies (see below). In the dialog that pops up add GLTools.lib:

Option 2: Saving the library and header files in your documents folder and adding them to your user or project include paths
The include path is the set of folders that VS examines when looking for header and library files to include in Open Visual Studio. In VS 2008 you add folders to the path from the Tools Options menu dialog. In VS 2010 this is no longer an option. In VS 2010 you can add folders to the path from the Properties Manager but you won't be able to do this unless you have a currently open project. i. Create a new (empty) project Select the menu option File New Project, Select the C++ General templates, and Empty Project, enter a name for your project and click OK. This will create a new, empty, project suitable for starting on an OpenGL project.

ii. Add freeglut and GLTools header files to the Include path Adding folders to the path is now done through the Property Manager. Select the menu option View Property Manager. The left hand pane of the VS IDE will change to show the property manager. You can resize this to make it more readable:

Expand the project if the full listing is not shown, then double click on one of the Microsoft.Cpp.Win32.user links to open the user properties dialog:

Select C/C++ - General to see the options to add additional include directories:

To add freeglut, add the freeglut include folder, which might be something like: C:\Users\admin\Documents\OpenGL\SB5\freeglut-2.6.0\include To add GLTools, add the GLTools include folder which might be: C:\Users\admin\Documents\OpenGL\SB5\Src\GLTools\include iii. Add the library file to the linker dependencies In the Property Manager, select Linker Input, then click on the Additional Dependencies (see below). In the dialog that pops up add the GLTools.lib and freeglut_static.lib files.

Notes
If you are moving projects between computers in the university and at home, you may get a range of compiler and linker errors if your project expects to find the library files at a specific location that exists in one setup but not the other I have put in a request for GLTools to be installed in the computer labs once this is done, there should be no need for you to add the freeglut and GLTools header and include files to your projects in the lab. This is the same as Option 1 above, and should make it easy to move projects between lab and home.

Test your installation


The easiest way to test whether your libraries are installed correctly is to run one of the examples from the SuperBible 5 book. Complete source for these is available from the link given at the start of these instructions. Close VS2010, then browse to where you have extracted the SB5 folder and open the project file: ...\SB5\VisualStudio2008\Chapter01\Block\block.vcproj Visual Studio 2010 will then startup and load the project you will be asked a few questions on whether to update for VS2010, and whether to keep a backup of the original project. You should not need to keep a backup unless you really want to. Once loaded, ctrl-F5 will compile and run the project. You will see a wireframe block on a surface. Press the space bar to rotate through a series of views. There is another test project available online at: http://www.box.net/shared/nyo764vfiy

Troubleshooting
My project compiles and runs OK, but I get lots of warning messages when compiling, e.g.
gltools.lib(GLBatch.obj) : warning LNK4099: PDB 'vc90.pdb' was not found with 'gltools.lib(GLBatch.obj)'

This is actually to be expected. You will get a lot of compiler warning messages to say that there is no debug information for the GLTools functions. If these warnings are distressing, you can switch them off from the project properties menus. I get a compiler error, e.g. fatal error C1083: Cannot open include file: 'GL/glut.h': No such file or directory The compiler is unable to find the glut.h file check that it has been placed in the correct location, e.g. C:\Program Files\Microsoft Visual Studio 10.0\VC\include\GL\ if you chose option 1. When I compile the program, it seems to compile, but fails during linking with a lot of error messages about unresolved externals, e.g.
1>Block.obj : error LNK2019: unresolved external symbol "public: void __thiscall GLBatch::End(void)" (?End@GLBatch@@QAEXXZ) referenced in function "void __cdecl MakeCube(class GLBatch &)" (?MakeCube@@YAXAAVGLBatch@@@Z)

The most likely explanation for this is that the lib file for either freeglut or GLTools has not been added to your project. Perhaps the compiler is looking for the file in the wrong location? If you used option 2, then double check that if the lib file has been added explicitly to the project that it is pointing to the correct folder. If you used option 1, check that have copied the lib file into the VS library folder, and that the lib file has been added to the list of additional dependencies (in this case you just need to add the name GLTools.lib or freeglut_static.lib) I get a linker error message which mentions libc (or libcmt) The user/project properties dialog has an option on the Linker Input page an entry to Ignore Specific Default Libraries. If you are having this problem, try adding libc.lib or libcmt.lib to this list. I get an rrror message during compilation/linking that complains about exit redefinition or something, e.g. error C2381: 'exit' : redefinition; __declspec(noreturn) >C:\Program Files\Microsoft Visual Studio 9.0\VC\include\stdlib.h(371) This is caused by the exit function being defined in both the stdlib and the glut libraries and these definitions conflict. The simplest solution is to add #define GLUT_DISABLE_ATEXIT_HACK before you #include <gl/glut.h> in your program. My program compiles and links, but fails when I try running it This may be caused by having out of date graphics drivers. Any Other Problem Other problems are possible if you encounter any other problems please post details to the discussion forum. As we find and solve problems, I'll add solutions to this list.

Anda mungkin juga menyukai