Mrmoen.com / Matt Moen
Technical Projects, Interests, and Tutorials

OpenGL with Visual C++ 2008 Express Edition

March 30th, 2008 by Matt Moen

OpenGL is a popular cross-platform library for 2-D and 3-D graphics programming. OpenGL comes with implementations on most operating systems and many compilers, including Visual C++ 2008 Express Edition, a modern, free IDE and compiler from Microsoft. Once VC++ 2008 is installed you simply need to create a new project and link to the correct libraries and headers to start using OpenGL.

New ProjectRun Visual C++ and create a new project:

  • Under the 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 source file for the project:

  • Under the Project menu select Add New Item (Ctrl+Shift+A).
  • Select C++ File (.cpp), enter a Name, and click OK.

Linker InputLink to the OpenGL libraries:

  • Under the Project menu select Project Properties (Alt+F7) at the bottom.
  • Select Configuration Properties → Linker → Input from the navigation panel on the left.
  • 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.
  • Type “opengl32.lib glu32.lib” in Additional Dependencies and click OK.

Red Square using OpenGLNow that your project is set up to use OpenGL you can start coding. Download opengl.cpp to begin with a basic Win32/OpenGL demonstration that compiles on VC++ 2008.

If everything is correct you should see a red square when running the code. Credit for this code goes mostly to examples from MSDN and NeHe.

To learn more about OpenGL programming there are several great online resources including NeHe Productions, OpenGL API Documentation, and GameDev.net.


Posted in Tutorials

8 Responses

  1. Neil Galloway

    This isn’t quite working for me. I have been having problems the last couple days getting this to work at all.

    The error I get is…

    —— Build started: Project: Test, Configuration: Debug Win32 ——
    Compiling…
    main.cpp
    Linking…
    MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
    C:\Documents and Settings\Neil Galloway\My Documents\Visual Studio 2008\Projects\Test\Debug\Test.exe : fatal error LNK1120: 1 unresolved externals
    Build log was saved at “file://c:\Documents and Settings\Neil Galloway\My Documents\Visual Studio 2008\Projects\Test\Test\Debug\BuildLog.htm”
    Test - 2 error(s), 0 warning(s)
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

  2. Neil Galloway

    Nevermind, I just fixed my own problem by going into Project -> Properties -> Linker -> System and changing the subsystem to Windows.

  3. Matt Moen

    My projects start with linker subsystem set to Windows when I create the project as described. Perhaps you had “Win32 Console Application” selected when you created the project instead of “Win32 Project”? Anyways, good to see you eventually got it working.

  4. Neil Galloway

    You’re right. I had selected Win32 Console Application when I created the project. I was following the directions from another tutorial at the time. Oh well. It is all good now.

    Thanks,

  5. akanksha

    On compiling the code it shows error like: glClearColour identifier not found . Like this it is throwing many errors. It is unable to locate the gl folder and all the header files.
    I am using microsoft VC++ 2008 and all the header files are present at:
    C:\Program Files\Microsoft SDKs\Windows\v6.0A\Include\gl
    How do I rectify?

  6. Matt Moen

    If VC++ is not locating your header files you’ll want to add that folder to your Additional Include Directories. That option can be found in Project Properties -> Configuration Properties -> C/C++ -> General. Good luck.

  7. akanksha

    I did that, but the prob still exists.

  8. dude

    Dude, I love you!

    I thought I never get this visual studio to work but with your tutorial I made it work. Thanks man.

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.