Click here to Skip to main content
11,923,517 members (70,106 online)
Click here to Skip to main content
Add your own
alternative version


13 bookmarked

A Simple OpenGL Window Using GLUT EP_OpenGL_001

, 19 Jun 2008 CPOL
Rate this:
Please Sign up or sign in to vote.
A Simple OpenGL Window using GLUT with Win32 Console Application


This is a simple C++ console application to create an OpenGL window using GLUT library. The code is from "OpenGL Programming Guide (Third Edition)". I tried to show how to download and include the GLUT library file. After including the GLUT file, compiling and running the code is very simple. The source code will not work if you don't have the GLUT library. Please, download the GLUT library and include it to the specific location (explained below).


You should be able to use Visual Studio 2005 and C++. You should also have some idea about OpenGL.

Using the Code


  1. GLUT Installation (download GLUT library).
  2. Copy and paste the GLUT library files to the specific locations.
  3. Create a C++ console application.
  4. Type the code, build and execute.

Step 1

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 ( (117 KB) ) link and download the zip file in your computer.

Step 2

Unzip the folder and 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 glut.h file and paste it to this directory C:\Program Files\Microsoft Visual Studio 8\VC\PlatformSDK\Include\gl. The installation of GLUT library files are done. However, if you using a different Windows or different Visual Studio, the directories might be different. I'm assuming that you are using Windows Vista and Visual Studio 2005.

Step 3

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.

Step 4

Type the code, build and execute.
Make sure to include the <GL/glut.h >.

//Include files
#include "stdafx.h"
#include <GL/glut.h >

Function "display(void)" displays a polygon.

void display(void)
    //Clear all pixels

    //draw white polygon (rectangle) with corners at
    // (0.25, 0.25, 0.0) and (0.75, 0.75, 0.0)
        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);
    // Don't wait start processing buffered OpenGL routines

Function init() initialises GLUT (sets the state):

void init(void)
    //select clearing (background) color
    glClearColor(0.0, 0.0, 0.0, 0.0);

    //initialize viewing values 
    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 main(int argc, char** argv)
    //Initialise GLUT with command-line parameters. 
    glutInit(&argc, argv);
    //Set Display Mode
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    //Set the window size
    //Set the window position
    //Create the window
    glutCreateWindow("A Simple OpenGL Windows Application with GLUT");
    //Call init (initialise GLUT
    //Call "display" function
    //Enter the GLUT event loop

    return 0;

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 GLUT library, it might take a little bit more time to compile the code.


  • Uploaded on 01/29/2008


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
United States United States

You may also be interested in...

Comments and Discussions

SuggestionConsider using Free Glut Pin
wcdeich46-Jun-15 17:04
memberwcdeich46-Jun-15 17:04 
QuestionOpeNGL Pin
maruch11-Jun-11 5:40
membermaruch11-Jun-11 5:40 
Question_tmain(... char ...) ????? Pin
emilio_grv 30-Jan-08 22:20
member emilio_grv 30-Jan-08 22:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.151125.3 | Last Updated 19 Jun 2008
Article Copyright 2008 by erjan123
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid