OpenGL and Borland

Up ] [ OpenGL ] DirectX ] Miscellaneous ] BMGLib ]


Using OpenGL with BC++ 5.02 and BCB

FREE COMPILER

People who need help with Borland's free compiler should visit Paul's web site or here.  You may want to return to this site afterwards since some of my comments apply to that compiler as well.

BASICS

Borland C++ Builder (versions 4+ ) comes with everything you need to make OpenGL applications.  The OpenGL functions are embedded in the import32 library and the header files can be found in Cbuilder4\include\gl.  BCB 1.0 and 3.0 must have the OpenGL DLLs, lib files, and header files added to the development environment.


The following directions only apply to Borland C++ 5.0x, BCB 1.0, and BCB 3.0.

BC++ comes with the OpenGL DLLs and header files (BC5\include\GL) that are needed by OpenGL.  Unfortunately, these are for version 1.0 of OpenGL.  You need to obtain the MS OpenGL DLLs to upgrade to version 1.1.  Execute the file that you download in a temporary directory.

If you are using an OS other than Windows 95 then copy the header files to bc5\include\GL.  Delete the DLLs and LIB files that were extracted from the download.  The DLLs are for Windows 95 and the LIB files are for VC++.  

BC++ has the OpenGL functions in its all-inclusive import32.lib (I think).  It also appears that BC++ for Windows NT has version 1.1 of OpenGL.  Also, the LIB files in bc5\lib\GL are useless.  You can delete them.

If you are running Windows 95, then you will need to create Borland compatible import libraries from the OpenGL DLLs.  Execute the following commands:

impdef opengl32.def opengl32.dll
implib opengl32.lib opengl32.def
del opengl32.def
implib glu32.lib glu32.dll

Note that implib does not work with opengl32.dll.   The glaux.lib file is a static library and you cannot convert it to a Borland compatible library using implib (see the discussion below for alternatives). 

Save the new header files in bc5\include\GL and save the import libraries in a place of your choosing (bc5\lib or bc5\lib\GL works for me).   Store the DLLs in your windows\system folder or anywhere in your path.  You need to manually add the import libraries to an OpenGL project.  BC++ does not automatically load them for you.  In BC++, this can be accomplished by right-clicking the exe file in the project window and selecting "Add Node" in the pop-up menu.  Select the lib files from the Open File dialog.  BCB 1.0 and 3.0 user should consult their documentation to determine how to add import libraries to their projects. 


The following comments apply to all versions of BCB and all Windows OSs.

If you are building an OpenGL app from scratch then Include windows.h before including bc5\include\GL\gl.h or bc5\include\GL\glu.h.

Most OpenGL examples (obtained from the web) should be compiled as WIN32 console applications.  Look for the main() or the WinMain() function.  Examples with main() are Win32 console applications.  Examples with WinMain are Win32 GUI applications.  These options can be set in your TargetExpert dialog box.  

There are no versions of OpenGL for any MS 16-bit operating system.

Do you have the latest OpenGL drivers for your card?  Go to  your card vendor's web site and download the latest drivers for your OS.  This is necessary when you upgrade your OS and (sometimes) when you buy a new computer.  Some computer manufacturers ship "old" drivers with a system.  

OpenGL VERSIONS & EXTENSIONS

Microsoft only supports OpenGL 1.1.  Card manufacturers must provide OpenGL support for any later versions or OpenGL extensions.  There are several libraries that will automatically detect and load OpenGL versions and extensions.

Lev Povalahev has published a library called glext.  I use this and it works with BCB.
The OpenGL Extension Wrangler Library (GLEW) is an open source project.
Sylvain Lefebvre has published the GLUX library. 
Nehe tutorials 22 and 24 demonstrate using some OpenGL extensions.  
Documentation of all OpenGL extensions can be found at the OpenGL extension registry.
There is an article about  detecting and loading new versions and extensions at Gamedev.net. 

REFERENCES & RESOURCES

I encourage all OpenGL newbies to visit www.opengl.org.  It has hundreds of links to very useful OpenGL sites.  Also, Paul Martz's OpenGL FAQ site is another excellent resource for OpenGL newbies.  Online help can be obtained in the OpenGL newsgroup.  Other useful links can be found on my Links page.

The following 2 books have been invaluable:

"OpenGL Programming Guide"  (AKA, the "Red Book")
Mason Woo, Jackie Neider, Tom Davis
Addison Wesley

This is a good introduction to fundamental and advanced OpenGL programming techniques.  Plenty of examples that use GLUT (see text below).  A "must have" for anybody that seriously wants to program with OpenGL.

"OpenGL SuperBible"
Richard S. Wright & Michael Sweet
Waite Group Press

This book is a good stand-alone reference for OpenGL programming, but what made it really invaluable was its focus on developing OpenGL applications on MS Windows operating systems.  Version 1 is available online (see my Links page).  Version 1 contains examples that show you how to create OpenGL/GUI applications with the Windows API, MFC, and OWL.  I have been told that the current version uses GLUT and does not discuss the other frameworks as well as the first version.

There are a plethora of web sites that demonstrate OpenGL programming techniques.  In my opinion, NeHe is the two best site for newbies.  

EXCEPTIONS

Math exceptions and access violations will occasionally cause your OpenGL applications to abort.  By default, MS ignores floating point exceptions; Borland does not.  Add the following line to the initialization section of your code:

_control87(MCW_EM, MCW_EM);  /* defined in float.h */

It will disable Borland's floating point exception handlers. 

Windows 9x applications may need to call

_clear87();
_control87(MCW_EM, MCW_EM);  /* defined in float.h */

before each frame is rendered.

GLAUX

I have never used GLAUX so please do not send me any questions about it.  

The OpenGL libraries contain a set of auxiliary windows functions defined in glaux.h that allow you to write OpenGL applications that will compile, link, and run on both a PC and a SGI workstation.  Unfortunately, the GLAUX.LIB file that comes with Borland C++ 5.0x will not link with your application.  

I have seen two remedies posted in the Borland and OpenGL newsgroups.

1) The GLAUX.LIB source is contained in MS's Win32 SDK (actually, it's the Multimedia Extensions SDK).  If this is true then you should be able build a Borland compatible version from it.  Ronald Praver has created a Borland compatible GLAUX.LIB file that you can download from his web site.  I assume that he used the SDK source to build the library. 

2) Use the glaux.lib that came with BC++ 4.5.  I have never tried this so I can't say that it WILL work.

GLAUX has known memory leaks and should not be used for application development.  The only reason for listing Mr. Praver's web site is because some tutorials on the Internet use GLAUX functions, particularly, the auxRGBImageLoad and auxDIBImageLoad functions.  I strongly suggest that you do not use these functions for applications that you develop.  There are several libraries on the Internet that you can use to load images into OpenGL.  Several can be found on www.sourceforge.net.  My BMGLib library can be used as well.  

GLUT

GLUT is a 3rd party add-on library for OpenGL created by Mark Kilgard.  It is not part of the official OpenGL distribution, but it is a widely supported OpenGL development library for writing cross platform OpenGL applications.  You can download the source for the GLUT Library (version 3.7.6) from Nate Robins' web site.  You can also obtain a DLL from there.  If you only get the DLL, then you will need to run implib to create a Borland compatible import library for it. 

I have BCB 5 project files that build the GLUT, MUI, GLE, and GLSMAP libraries.  It also contains projects files to build all of the examples that come with the GLUT library.  You need to obtain the glut-3.7.6-src.zip file from Nate's web site.  Next, download the GLUT 3.7.6 library source and projects (523 KB) from my web site.  Unzip Nate's file to "C:\Projects\OpenGL" (make sure the "use folder names" box is checked if you are using WinZip).  Next, unzip my file to "C:\" (again, make sure the "use folder names" box is checked).  My file adds the project files that build the libraries and examples.  It also replaces a few source files that would not compile in Nate's version and fixes a bug with the pop-up menus.  

For you folks using the free compiler Download GLUT 3.7.6 SDK (99.4 KB) which contains glut.h, glut32.lib, and glut32.dll.

You can use GLUT with Builder.  Simply create a console application and link the GLUT library with it.  You should not mix GLUT with the VCL.  GLUT is essentially an interface with the Windows API.  This interface will probably conflict with the VCL application class.  You must place glut32.dll in your path or in the folder that contains your executable.  You must place glut32.lib in your library search path or the folder containing your project.  The GLUT.H file automatically links glut32.lib to your project.  BCB users must add $(BCB)\lib\psdk to the library search path; otherwise, the linker will not be able to find GLU32.LIB which is automatically linked to the application by the GLUT.H file.  You must also add WIN32 to the list of defined conditionals; otherwise, you will have errors when trying to compile the code.

Borland compatible GLUT libraries for BC++ (not Builder) can be found here

There are at least 4 GLUT enhancements that add GUI features to GLUT.  One, MUI, is contained in the GLUT distribution.  You can find links to the other libraries on my Links page.

Borland C++ Builder OpenGL Components and Tutorials

There are several places on the web that discuss using Builder with OpenGL.  All of these sites create OpenGL components from the VCL classes.  A Borland TI article can be found at Borland's web site.  BCBDEV has a brief OpenGL tutorial.   A tutorial can be found at The Bits (this tutorial is old and the information, especially the discussion about SGI's DLLs, is no longer accurate)Bytamin-C has a 3-part OpenGL tutorial.    Alan Garney has a shareware component and several of the "Red Book" examples rewritten for his component.  SignSoft has commercial OpenGL components that you can download and test.   Lucian Wischik has a freeware component and some information about creating screen savers and hardware acceleration.  Allan Petersen has a freeware OpenGL component, a GLAUX replacement, and has ported several of NeHe's OpenGL tutorials to BCB.    Daniel Plakosh (recommended) has a freeware OpenGL component as well.  Christian Kindahl has converted all of NeHe's tutorials to BCB (version 6).

BCB 4 and 5 have 2 examples that show you how to use OpenGL with Builder.

RHETORIC

OpenGL versus DirectX