Monkey Fighter Monkey Fighter
Academic Help Help Search Search Shop Shop

Using NeHe's OpenGL Tutorial with C++ Builder

NeHe OpenGL screen shot

If you want to learn OpenGL programming, a good place to start is NeHe's OpenGL Tutorials. This site contains all the information you need to code OpenGL on a windows box. You can download all the code for all the tutorials. And, I have yet to find one that I can't compile and run correctly.

The NeHe tutorial code was developed for M$ Visual C++. However, many code monkeys, like myself, prefer to use Borland's C++ Builder. This is especially true now, since BuilderX is royalty free and available for download at C++ BuilderX. If you prefer to use C++ Builder, you will find that NeHe's code won't link. This might prompt you to download the code translated specifically for C++ builder as I did. Unfortunately, I was disappointed with the translation. I isn't consistant with NeHe's simple one file solution. Instead, it is arranged in a modular layout. This is ideal for professional software engineering projects. But, we just want to read the tutorial and play with the code. The C++ Builder translation varied to much from the original design for me. So, I debugged the project and found that it is very easy to get the original Visual C++ code to compile, link, and run using C++ Builder and code only needs to change by two extra lines.

You can use the Visual C++ code with C++ Builder (or BuilderX). Just follow these easy steps:

1. [Builder] Be sure that you have all your OpenGL Files. You probably have all of them except glaux.lib. If any are missing, use the link in the right sidebar to grab a copy and install it in your lib directory.
1. [BuilderX] Same as for Builder except your root directory will likely be CBuilderX.

CBuilder\Include\GL C:\Windows\System CBuilder\Lib
glaux.dll glaux.lib

2. [Builder] Double click the Lesson#.ccp file. Builder will ask you if you want to create a project. The obvious answer is 'yes'. If you got stumped here, go back to playing games because you are in way over your head.
2. [BuilderX] Create a new GUI application by selecting File|New... Then, double click the New GUI Application icon. A dialog box with two text boxes will appear, one labeled name and the other directory. Set the directory text box to the directory of the NeHe tutorial that you want to compile. Then, click next. You are now asked what OS to compile the code for. Make sure these match your current OS and click next. Now, you are asked to add files to your project. Click the add button and add the lessonX.cpp file. Then, click the add button again and add glaux.lib. Click Finish and you are ready to compile.

3. [Builder] Add glaux.lib to your project. The linker needs glaux.lib. So, add it to your project by selecting Project|Add to Project. A file dialog will appear. Select glaux.lib with it.

4. [Builder] Add code to prevent floating point errors. Unlike Visual C++, Builder propagates floating point errors up the code like a well behaved C++ compiler should. However, we want to ignore all of them. This is done easily by adding the following two lines. Add the first line somewhere at the beginning where you included the rest of the header files. Add the second line before any OpenGL code executes. I like making it the first executable line of WinMain().

	#include <float.h>
	_control87(MCW_EM, MCW_EM)

5. Compile and run the code!

That's all you should need to get the code running. However, if you are like me, you tend to rush the learning process. For example, I like to drag and drop zip files from Winzip to their permanent directory. However, most of the later tutorials have bitmap files which should be in a data subdirectory and that method of extraction doesn't retain subdirectory information. This silly oversight caused me to needlessly trace though the code to find out why the program was shutting down prematurely. Also, be aware that CBuilderX compiles the .exe to a subdirectory of the .cpp code. For windows it is something like /Windows/release. In such a case, the data subdirectory should be placed in /Windows/Release directory. Hope this helps and happy coding...


C++ BuilderX

OpenGL Game

3D Asteroids


NeHe Tutorials

Free Books

The OpenGL "RedBook"
The OpenGL "BlueBook"

Shop For Books

- OpenGL
- C++ Builder
- Game Programming
- Hacking

Copyright © 2005, Robert Walsh, All Rights reserved.