OpenGL and glut in C++ with MS Visual Studio 2008 (MSVS9)

OpenGL support come with many IDEs, programming  environments and compilers. Likewise MSVS9 comes with built in support for OpenGL so that you can use all features of gl and glu libraries simply. To use glut support we need to download and add the glut support. Let us do both one by one.

OpenGL (gl and glu)

Creating Project
Creating Project

Hopefully you have already installed MS Visual Studio 2008 or MS Visual C++ 2008. If so, let us do the following,

  • Create an empty C++ Win32 application.
    • From File menu select New → Project (Ctrl+Shift+N).
    • Select Win32 Project, enter a Name, and click OK.
    • In the Wizard click Next, then check the box next to Empty Project, and click Finish.
  • Add a new C++ source file
    • Under the Project menu select Add New Item (Ctrl+Shift+A).
    • Select C++ File (.cpp), enter a Name, and click OK.
  • Link to the OpenGL libraries
    Linking Libs
    Linking Libs
    1. Under the Project menu select Project Properties (Alt+F7) at the bottom.
    2. Select Configuration Properties Linker Input from the navigation panel on the left.
    3. Select All Configurations from the Configuration drop-down box at the top of the dialog. This ensures you are changing the settings for both the Debug and Release configurations.
    4. Type “opengl32.lib glu32.lib” in Additional Dependencies and click OK.
  • Now, you can start coding. You can download GLDemo.cpp to begin with a demo that, if executed(Cntrl+F5), will show a window with blue triangle.

GLUT with a Win32 console application

Download and Install GLUT

Download and Install GLUT


Assuming, you already have MSVS9 installed, you have OpneGL libraries installed and placed in exact places. But, if one need to use the functionality of glut library it is necessary to download and install the very library. Please, do the following:

  • Download the original GLUT library from Nate Robins’ site
  • Unzip the download and copy files as instructed below,
    • glut.h to the folder C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl\
    • glut32.lib to the folder C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib\
    • glut32.dll to the folder C:\Windows\System32\
  • You are now ready to use GLUT!

N.B.: For Visual Studio 2010 check later post, glut in MS Visual Studio 2010 (MSVS10)

Working With GLUT

Now, have your GLUT set up, you can work with GLUT and OpenGL in whatever way you like. Meanwhile, let me place a simple demo:

  • From File menu select NewProject (Ctrl+Shift+N).
  • Select Win32 Console Application, enter a Name, and click OK.
  • In the Wizard click Next, then check the box next to Empty Project, and click Finish.
  • Add new source file (*.cpp) from the project menu [Source File → Add → New Item → Visual C++ → Code → C++ File (.cpp)] enter a Name and click add
  • You can use a demo file from here (GLUTdemo.cpp). If execute, you will see a triangle to appear; you can move it left[j] and right[l] ward and rotate/stop rotate[r] and exit app[Esc].
  • In a later post we will discuss coding in OpenGL and GLUT and make a simpler start-up demo, with short description on each line. [⇗]

It is all in short for now; I hope you this has been helpful. For introductory tutorial on programming OpenGL in C/C++ please try my next post in this category » Beginning Device-independent Graphics Programming with OpenGL (using GL, GLU & GLUT)

I would like to place some links that I found helpful, and also thank the authors hereby, as follow:

I faced some problem in using OpenGL libraries and GLUT library and eventually found some solution from the web. Hence I am posting this blog to share some help in one place that may help other guys and girls.

40 thoughts on “OpenGL and glut in C++ with MS Visual Studio 2008 (MSVS9)

  1. aita to just library add kora and open new file er tutorial…..
    plz write abt how to code in opengl? or some documentation of gl functions, or some application code as like as “hello world”…thanks best of luck


    1. The demos are of little help here and you get basic idea of OpenGL programming. I will try to do some more hello worlds or “how to”s.
      This post is just a solution to a problem that has been troubling some other guys also.


  2. In order for this to work for VS2010, I had to modify:
    Type “opengl32.lib glu32.lib” in Additional Dependencies and click OK.


    Type “opengl32.lib; glu32.lib;” in Additional Dependencies and click OK.

    Thanks for the tutorial!


  3. I’m using MSVS 2010, i’ve followed the tutorial, I input the additional dependancies as Mike K. suggested, but i’m getting these 2 errors:

    error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup c:\Users\Jay\documents\visual studio 2010\Projects\GLUT test\GLUTtest\MSVCRTD.lib

    error LNK1120: 1 unresolved externals c:\users\jay\documents\visual studio 2010\Projects\GLUT test\Debug\GLUTtest.exe


  4. Hi
    Thats a real good tutorial. However GLUT doesn’t work yet.. I have MS visual Studio 9 and installed glut as mentioned . I open a new project in MS Visual Studio and don’t even have option of Win32 project. there is a console application or empty project option. How can i use GLUT in MS Visual studio?? pls help.


    1. You can work with Console application, and it should be an Empty Project to run codes provided with my webnotes.
      For problems with MSVS installation other fellows might help; I never had to face such problem though.


  5. when i try to compile GLUTdemo.cpp I got an error saying glut32.dll is missing hence cannot start … can somebody help me with that plz


    1. If you are in MSVS9 (Visual Studio 2008) please, try to follow the steps explained in the blog. Ensure files are in exact directories. And ensure, that you are trying to compile a project and not a file


  6. hi……
    am having C:\Program Files\Microsoft SDKs\Windows\v7.0A\Lib
    instead of C:\Program Files\Microsoft SDKs\Windows\v6.0A\Lib
    will it work if i add those header file and library file?


  7. The mistake that I was making was that I was copying the dll files to the System32 folder when I was actually using a 64 bit system, so when I copied the dll files to the SysWOW64 folder the problem was fixed. Thanks for help!


Leave a Reply to Hajeeali(Arif) Cancel reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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