OpenGL with Visual C++ 2008 Express Edition
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.
Run 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.
- 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.
Now 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
April 7th, 2008 at 9:54 pm
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 ==========
April 7th, 2008 at 10:10 pm
Nevermind, I just fixed my own problem by going into Project -> Properties -> Linker -> System and changing the subsystem to Windows.
April 7th, 2008 at 11:52 pm
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.
April 8th, 2008 at 1:45 am
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,
April 22nd, 2008 at 11:30 pm
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?
April 23rd, 2008 at 12:24 am
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.
April 23rd, 2008 at 8:51 am
I did that, but the prob still exists.
June 16th, 2008 at 5:05 am
Dude, I love you!
I thought I never get this visual studio to work but with your tutorial I made it work. Thanks man.