This is a very simple C++ console application that creates a simple OpenGL window. The source code is from the book "OpenGL Programming Guide (Third Edition)." This article will explain how to download and include the GLUT library. Once you include the GLUT library, it's very simple to build and execute the code. It explains also the OpenGL code that is used in this program.
You should be able to use Visual Studio 2005 and C++. You should also have some idea about OpenGL.
Using the Code
- GLUT installation (download the GLUT library)
- Copy and paste the GLUT library files to the specific locations
- Create a C++ console application
- Type the code, build and execute
Before you even start a new project, you have to download the GLUT library. You can get the latest version from this link: GLUT 3.7.6 for Windows. Click this (glut-3.7.6-bin.zip (117 KB) ) link and download the ZIP file into your computer.
Unzip the folder, copy the glut32.dll file and paste it to C:\WINDOWS\system. Copy the glut32.lib file and paste it to this directory: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Lib. The last step is to copy the glut.h file and paste it to this directory: C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\gl. The installation of the GLUT library files is done. However, if you using a different Windows or different Visual Studio version, the directories might be different. I'm assuming that you are using Windows Vista and Visual Studio 2005.
Create a C++ console application. You don't need a Windows application. From Visual Studio 2005, select File -> New -> Projects. Select project types Visual C++ -> Win32 and create a Win32 console application.
Type the code, build and execute. Make sure to include the
#include <GL/glut.h >
display(void) displays a polygon:
glVertex3f(0.25, 0.25, 0.0);
glVertex3f(0.75, 0.25, 0.0);
glVertex3f(0.75, 0.75, 0.0);
glVertex3f(0.25, 0.75, 0.0);
init() initialises GLUT (sets the state):
glClearColor(0.0, 0.0, 0.0, 0.0);
glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0);
Main function: make sure to change the command-line parameter
_TCHAR* to char**.
int _tmain(int argc, char** argv)
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("A Simple OpenGL Windows Application with GLUT");
Variable or class names should be wrapped in
<code> tags like
Points of Interest
Actually, this program is a very simple OpenGL program. However, if you are new and if you don't know how to initialise the GLUT library, it might take little bit more time to compile the code.
Uploaded on 01/29/2008