administration mode
Pssst...Ferdy is the creator of JungleDragon, an awesome wildlife community. Visit JungleDragon


Article: Portable openGL programming in C++ »

FERDY CHRISTANT - JAN 22, 2007 (08:22:47 PM)

  Every now and then, I get tired of the usual business web application, no matter the platform. It is at times like these, that I want to do something more creative, and fun. For a while now, I've been having ideas about using OpenGL to implement something cool. They are ideas that I probably will never implement due to a lack of time, but I decided to at least learn something about the basics of openGL.

This short article explains how you can get started in OpenGL programming, and how to develop portable code. You would think that others have done this before, which is true. Yet, I could not find any concise article on how to achieve exactly what I wanted. I will not bother you with what OpenGL is, you can find that out yourself here.


I've chosen to develop my OpenGL code on Windows using Visual C++, which is part of Visual Studio. You can download the free express edition here, or use Visual Studio if you're lucky to have a license for it. Note that the code can be produced in any IDE, but this seems like the easy choice on Windows. Later I might add setup instructions for Eclipse.

Setting up the IDE

With our IDE in place, it is time to create a first project and configure the link settings. Luckily, this is described in detail here. Be sure to follow the exact instructions in that article. But wait, we're not done yet. In order for the resulting .exe file to be usable on other computers that do not have Visual C++ installed, we need to change two more settings:

In the project properties Window, section C/C++ ->Code generation, set the "Runtime library" value to "Multi-threaded (/MT)" for the release configuration (upper left dropdown), and "Multi-threaded Debug (/MTd)" for the debug configuration.

Adding an example

With the IDE and our project properly configured, it is now time to test some example code. Download the triangle example from this list of examples, and extract the file to a location on your hard drive. Next, in Visual C++, right-click on your project in the solution explorer, and chose "Add->Existing item..". Browse to the main.cpp file of the example and import it.

To run the example, click the play button in Visual C++. When successful, a window with a triangle will appear:


Distributing the application

You have just run the application from Visual C++ successfully. This has resulted in a .exe file in the debug directory of your application. You should not distribute that .exe file to your users, however.  First, we need to build a release, not a debug assembly. A release assembly results in a significantly smaller .exe file. To do so, in Visual C++ go to Build->Configuration Manager, and then set the active solution configuration to "release". Next, rebuild the application, by right-clicking on the project in the solution explorer, and chosing "Rebuild".

The resulting .exe file can be found in the "release" directory of your project. Note that you still cannot distribute this .exe file by itself to your end users. The reason is that the application depends on two .dll files: glut32.dll and opengl32.dll. Opengl32.dll is shipped in Windows 2000 and Windows XP by default, glut32.dll is not. To be absolutely sure that your .exe will run on any Windows version, you need to ship both files with the .exe, in the same directory, or create an installer that installs these files in the window system directories. Unfortunately, it is not possible to statically link to these libraries.

Next steps

Our OpenGL application is now portable across all Windows platforms, which is great, but what about other platforms? Technically, apart from the way of building the application, nothing about the code is platform-specific. This means that our code is fully portable. I will demonstrate this in a future follow-up to this article.

The idea

This idea I am having, what led me to OpenGL in the first place. I've been thinking about 3D interfaces applied to common desktop functionality. For example, a 3D way to navigate and search through files. While I do question the added value of such an interface, it would be one awesome experiment. Now that I have OpenGL development properly setup, I am excited and frustrated at the same time. Excited that I have the power to implement the experiment for real. Frustrated that I'm a graphic programming rookie and will probably never have the time to implement the project.

Share |

Comments: 9
Reviews: 2
Average rating: rating
Highest rating: 5
Lowest rating: 4


JAN 23, 12:32:12 AM

comment » Cool! You might have visited it already, but NeHe ( is quite popular when it comes to OpenGL tutorials, and goes from the simple to quite advanced. Also, Google for the OpenGL red book and blue book - I think both are still available for free online: they're the bibles! «


JAN 23, 01:16:31 PM

comment » Thanks, Colin. While I do remember once ending up at that site, I did not bookmark it at the time. Now that I am having a closer look at it, it is simply amazing. Found the redbook as well, great! «

COMMENT: MOHSEN CHOOBDAR emailhomepagerating

JUL 12, 04:59:04 PM

comment » i want learning OpenGL

can u help me?

tank u «


MAR 29, 2008 - 13.33.26

comment » Nice tutorial! Thanks! «


APR 6, 2009 - 01:48:09 PM

comment » it is nice but i am searching for a demo project for satellite communication could u help me. 23 23 23 «


MAY 4, 2009 - 07:12:44 PM

comment » dunk dikirimm master Portable openGL programming in C++ nya saya butuh banget Boss.. ma tu Soft Portable..

Heheh.. 18 kalo ada tolong di kirim ke e-mail saya ya Boss..

Terima Kasih.. 18 25 «


AUG 18, 2010 - 11:35:20 ق.ظ

comment » hi

please i need the open GL code for drawing mobile k800i

please send for mi whith my «

COMMENT: VALKPIM emailhomepage

FEB 25, 2011 - 04:25:59 PM

comment » i want tutorial ....can you help me. thanks «


OCT 1, 2013 - 03:32:52 PM

comment » thank you «

Was this document useful to you?
rating Awesome
rating Good
rating Average
rating Poor
rating Useless
required field
required field HTML is not allowed. Hyperlinks will automatically be converted.