Help end child hunger

Setup Basics

 
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

Windows (/SUBSYSTEM:WINDOWS)

Then go to:

Project Properties » Linker » Command Line

and add:

/ENTRY:mainCRTStartup

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
 

  10 Responses to “Setup Basics”

  1. You may add
    #define _CRT_TERMINATE_DEFINED
    before
    #include
    to get rid of “error C2381: ‘exit’ : redefinition;”

  2. Thanks for the instruction on removing the console window! That was huge for me. I don’t know why this isn’t in more tutorials as I think most people would be using Microsft Visual Studio.

  3. Very Nice Tutorials,

    And use the freeglut available @ http://freeglut.sourceforge.net/index.php.
    OR
    download the source code, if you are thinking of custom made DLL’s such as for 64-bit!
    Use the CMake to generate the project files and compile your own version!

    Enjoy!

    Regards.

  4. I very appreciate your work for making this tutorial. I was looking for how to start, and i got a lot of error just want start my openGL program. But your words here enlight me to make my research works.. Thx a lot, it is a great !!

  5. Hi,
    Thank you for this tutorial !!
    I followed your instructions to setting VS (2009). Actually, I would like to have a console window next to the opengl window because sometimes is useful to send “messages” through printf. But I have only the opengl window, where printf does not work….
    If you have any suggestion…

    • HI, I found the answer myself: if I include the line
      #pragma comment(linker,”/subsystem:\”windows\” /entry:\”mainCRTStartup\””)
      at the beginning of the code I have only the openGL window else I have both (for a Win 32 console application)

  6. I would go for C++. With the size projects take its better to keep the code organized at the possible expense of some memory.

  7. For visual studio users, this might be a useful GLUT installation guide, too;

    http://www.cs.uiowa.edu/~cwyman/classes/common/howto/winGLUT.html

  8. Can you give me a direct link on where to download the latest version of this 3 files
    * glut.h
    * glut32.lib
    * glut32.dll

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: