home Software OpenGL and Visual Studio Express 2008

OpenGL and Visual Studio Express 2008

I recently set up Visual C++ 2008 Express Edition and OpenGL on my Windows XP and Windows Vista computers. I had a few issues, but it is working now. I have a step by step tutorial below and also outlined some of the issues I had.

This is also a guide on just setting up your development environment on Windows for OpenGL programming. If you are like me, I am starting out doing game programming and want to add OpenGL graphics.

The OpenGL tutorials I am using are from NeHe’s Website and here is a Visual C++ 2008 and OpenGL Guide I used.

Getting OpenGL to Work With Visual C++ 2008

Follow each step, unless you have already done one of these steps.

1. Install Visual C++ 2008 Express Edition

This is a free C++ IDE from Microsoft that is an excellent tool to start with, if you are interested in programming on a Windows environment.

You can find Visual C++ 2008 on the Visual Studio Express download page on Microsoft’s site. It only works on Windows XP and up. If you have an older version of windows you might want to find Visual C++ 2005 and then use this Visual C++ 2005 and OpenGL tutorial.

2. Install Windows SDK for Windows Server 2008 and .NET Framework 3.5

This is the equivalent to the Windows´┐Ż Server 2003 SP1 Platform SDK that Visual C++ 2005 users installed. It contains the main OpenGL libraries. You can download the Windows SDK for Windows Server 2008 and .NET Framework from the Microsoft website.

The installation will take a little while.

Dell Canada Inc

3. Install the GLUT Libraries

These are additional libraries that come in handy down the road. Some code samples you find may use them, so I find it best to just have them around right off the bat.

GLUT itself is a bit old, but there is another one called freeglut that is a little more actively maintained. I install both of them. Download freeglut from the freeglut SourceForge page. I download the original GLUT from Nate Robins’ site.

For both downloads, unzip them and do the following:

  1. Copy all the .h files into the C:\Program Files\Microsoft SDKs\Windows\v6.1\Include\GL folder. This should be glut.h, freeglut.h, freeglut_ext.h, and freeglut_std.h.
  2. Copy all the .lib files into the C:\Program Files\Microsoft SDKs\Windows\v6.1\Lib folder. This should be freeglut.lib and glut32.lib.
  3. Copy all the .dll files into the C:\Windows\system32 folder. This should be freeglut.dll and glut32.dll.

4. Create Your First Project

Create a project in Visual C++ with whatever name you like and set the template as Win32 Project. Click OK.

Click Next on the following screen and you will be taken to Application Settings. Check on Empty Project and then click OK. Your new project has been created.

Declare the dependencies for your project.

  1. Click on Project -> [project name] Properties.
  2. Expand Configuration Properties.
  3. In the Configuration dropdown, select All Configurations.
  4. Select Linker -> Input.
  5. In the Additional Dependencies field, enter in GlU32.Lib OpenGL32.Lib freeglut.lib glut32.lib. Then click OK.

5. Create Your First Source File

I recommend a .cpp file. I recommned downloading the source code from NeHe’s Lesson 2 and copying into the file you just created.

Press F7 to compile it and F5 to run it.

It should be working at this point. If not, post a comment and I will try and help out.

Problems Setting Up OpenGL and Visual C++ 2008 Express Edition

Character Set Error

When I try to compile the project, I get the following error:

------ Build started: Project: Test, Configuration: Debug Win32 ------
Compiling...
main.cpp
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(87) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [29]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(92) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [34]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(99) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [31]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(105) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(109) : error C2664: 'UnregisterClassW' : cannot convert parameter 1 from 'const char [7]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(111) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [28]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(147) : error C2440: '=' : cannot convert from 'const char [7]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(151) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [37]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(169) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [94]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(176) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [24]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(209) : error C2664: 'CreateWindowExW' : cannot convert parameter 2 from 'const char [7]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(212) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [23]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(241) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [34]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(248) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [35]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(255) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [27]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(262) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [37]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(269) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [41]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(281) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [23]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(358) : error C2664: 'MessageBoxW' : cannot convert parameter 2 from 'const char [42]' to 'LPCWSTR'
        Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Build log was saved at "file://c:\Documents and Settings\Neil Galloway\My Documents\Visual Studio 2008\Projects\Test\Test\Debug\BuildLog.htm"
Test - 19 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This can be fixed by doing the following:

  1. Project -> [projectname] Properties
  2. In the Configuration dropdown, pick All Configurations.
  3. Expand Configuration Properties.
  4. Select General.
  5. Change the Character Set to be Use Multi-Byte Character Set.

The errors should go away the next time you compile.

Can’t Include glaux.h

The first time I compiled, I received the following error:

—— Build started: Project: Test, Configuration: Debug Win32 ——
Compiling…
main.cpp
c:\documents and settings\neil galloway\my documents\visual studio 2008\projects\test\test\main.cpp(12) : fatal error C1083: Cannot open include file: ‘gl\glaux.h’: No such file or directory
Build log was saved at “file://c:\Documents and Settings\Neil Galloway\My Documents\Visual Studio 2008\Projects\Test\Test\Debug\BuildLog.htm”
Test – 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This is because the glaux.h has not been added to the include folder. You can do this if you want, but the glaux.h library is old and out dated based on most user comments on the internet. A lot of the examples, especially from NeHe, do not even use the code inside it anymore. I can usually just comment out or remove the

#include 

from the code and it will be fine.

Set Up Dependencies For The Project

When the dependencies are not there, I received the following error trying to compile:

------ Build started: Project: OpenGLTest, Configuration: Debug Win32 ------
Compiling...
WinMain.cpp
Compiling manifest to resources...
Microsoft (R) Windows (R) Resource Compiler Version 6.0.5724.0
Copyright (C) Microsoft Corporation.  All rights reserved.
Linking...
WinMain.obj : error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function "void __cdecl ReSizeGLScene(int,int)" (?ReSizeGLScene@@YAXHH@Z)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function "void __cdecl ReSizeGLScene(int,int)" (?ReSizeGLScene@@YAXHH@Z)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "void __cdecl ReSizeGLScene(int,int)" (?ReSizeGLScene@@YAXHH@Z)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function "void __cdecl ReSizeGLScene(int,int)" (?ReSizeGLScene@@YAXHH@Z)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glHint@8 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glDepthFunc@4 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glEnable@4 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glClearDepth@8 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glShadeModel@4 referenced in function "int __cdecl InitGL(void)" (?InitGL@@YAHXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function "int __cdecl DrawGLScene(void)" (?DrawGLScene@@YAHXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function "int __cdecl DrawGLScene(void)" (?DrawGLScene@@YAHXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function "int __cdecl DrawGLScene(void)" (?DrawGLScene@@YAHXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glTranslatef@12 referenced in function "int __cdecl DrawGLScene(void)" (?DrawGLScene@@YAHXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "int __cdecl DrawGLScene(void)" (?DrawGLScene@@YAHXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function "void __cdecl KillGLWindow(void)" (?KillGLWindow@@YAXXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function "void __cdecl KillGLWindow(void)" (?KillGLWindow@@YAXXZ)
WinMain.obj : error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function "int __cdecl CreateGLWindow(char *,int,int,int,bool)" (?CreateGLWindow@@YAHPADHHH_N@Z)
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup C:\devkitPro\projects\OpenGLTest\Debug\OpenGLTest.exe : fatal error LNK1120: 19 unresolved externals Build log was saved at "file://c:\devkitPro\projects\OpenGLTest\Debug\BuildLog.htm" OpenGLTest - 20 error(s), 0 warning(s) ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

To set up OpenGL dependencies for a project, refer to the declaring the dependencies section in Create You First Project section above.

That should fix the problem, try recompiling now.

Change the Application Type

I have also experienced the following error when I compile:

------ Build started: Project: OpenGLTest, Configuration: Debug Win32 ------
Linking...
MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
C:\devkitPro\projects\OpenGLTest\Debug\OpenGLTest.exe : fatal error LNK1120: 1 unresolved externals
Build log was saved at "file://c:\devkitPro\projects\OpenGLTest\Debug\BuildLog.htm"
OpenGLTest - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

This was caused by not picking the right application type when I created the project. In this example, I chose Win32 Console Application at the startup. To change it, I did the following:

  1. Click on Project -> [project name] Properties.
  2. Expand Configuration Properties.
  3. In the Configuration dropdown, select All Configurations.
  4. Select Linker -> System.
  5. Change the Subsystem field to be Windows (in the case it was Console or try the opposite if it already is Windows). Click OK.

One thought on “OpenGL and Visual Studio Express 2008

Leave a Reply