Using NeHe's OpenGL Tutorial with C++ Builder
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
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:
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.
Same as for Builder except your root directory will likely be CBuilderX.
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.
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.
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.
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().
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...