|Prev: Index||Next: Initialization|
What you need
In order to write applications with GLUT you should have the latest version – 3.7.6. You can find the windows binary files (h lib and dll), as well as GLUT’s source code in Nate Robins site.
In order to write a C application using GLUT you’ll need three files:
- glut.h – This is the file you’ll have to include in your source code. The common place to put this file is in the gl folder which should be inside the include folder of your system.
- glut32.lib (Windows version) – This file must be linked to your application so make sure to put it your lib folder.
- glut32.dll (Windows) – You could place the dll file in your exe’s folder.
A clean house
If you’re serious about OpenGL, sooner or latter you’ll start adding other libs to your application. Having them all in one place is a good idea to keep everything updated, and even in the case where you want to move all your stuff to other computer.
Hence my suggestion is to create a folder to keep all these files. This folder should have three sub folders, namely includes, libs and dlls. Then place all the files mentioned above in these sub folders. Whenever you need more libs just keep adding them to this folder structure.
Setting up in Visual Studio 2010
I’m not an expert in VS, so this is probably not the most efficient way of doing things. It should work if you follow these instructions step by step. If you know of a better/faster way of doing things let me know and I’ll update the tutorial.
First make sure you start VS in C or C++ mode. Select File->New Project and a dialog opens. Select “Win32 Console Application” and give a name to your project. Press OK to move on.
In the next dialog press “Next”. In the next screen select “Console Application and check “Empty Project”. Press “Finish” and your project is ready.
Now go to solution explorer. If you can’t see it go to “View” and select “Solution Explorer”. The project you just created has a set of ‘folders’. Right click on “Source Files” and select “Add->New Item”. In the dialog for the new item select C++ or C File, give it a name and you are ready to start coding.
After you got the code right and your app executes you may notice that two windows are opened: your window with the OpenGL rendering, and a console window. The console window is useful in case you want to print something out with printf. However, at the end of the day you may want to get rid of it.
Ricardo has posted a comment on another page with a solution to get rid of the console window. Thanks Ricardo. Go to:
ProjectProperties » Linker » System » SubSystem
and set the property to
Then go to:
Project Properties » Linker » Command Line
to Additional Options.
A final note, you must tell VS where it can find the include and lib files for GLUT. Right click on the project in Solution Explorer window and select "Properties". In the left side if the properties dialog select VC++ Directories and add to the right side your path to the include and lib files.
Notes on Using OpenGL with VS.NET
Many people have experienced a small problem when using VS.NET to build OpenGL applications: a compiler error that, as far as I know, seems to exist only in these compilers (VS 2003 and 2005, VC 6.0 is OK). Here is the actual text generated by VS 2005:
c:\programs\microsoft visual studio 8\vc\include\stdlib.h(406) :
error C2381: 'exit' : redefinition; __declspec(noreturn) differs c:\opengl\toolkits\includes\gl\glut.h(146) : see declaration of 'exit'
This problem seems to be caused by the inclusion of glut.h before stdlib.h. Reversing the order solves the problem. The following code causes the compiler error:
#include <GL/glut.h> #include <stdlib.h>
But when including first stdlib.h the problem disappears:
#include <stdlib.h> #include <GL/glut.h>
Do let me know if you have any tips so that I may include them in here and save time to all those who starting to learn OpenGL.
OK, so all is set, lets learn how to write GLUT applications. If there is anything that is not quite clear please let me know and I'll try to improve it. Your feedback is important.
|Prev: Index||Next: Initialization|