Trying to write OpenGL programs in the Borland C++ environment can be challenging at best. Back in 1999, after my search of every known search engine I knew of, I ended up with only a couple of links. They are
To me, that was pretty amazing. But perhaps this was at the beginning of when people wanted to do this. I have since moved to using Visual Studio, but I still receive comments on the usefulness of this page, so I'll leave it here.
This web page will mainly detail the process of using the GLUT library. Since the files may be updated with newer versions, I will only provide links to each required file. A good place to start for all OpenGL info is OpenGL.org. If there are any problems with this process, please let me know so I can update the page.
First of all, you will need an OpenGL implementation. Unless your video card was
made before 1997, you should have the .DLL files already. Borland by default comes
with the necessary header files in
c:\bc5\include\GL. It also comes
with the library files opengl32.lib and glu32.lib. However, I was not able to get
Borland to work with these library files. You ONLY need to download
this file if you are missing the header files (or you have an old video card).
Do the following:
- Run opengl95.exe in
c:\windows\temp\openglso that the files are extracted there.
- Go to your
c:\bc5\includedirectory and make a GL subdirectory. Copy gl.h, glaux.h, and glu.h from
- If you HAVE an old video card, copy glu32.dll and
c:\windows\system. These are software rendering drivers and if you overwrite you hardware accelerated drivers, your programs will run much slower.
- Do NOT copy the .lib files anywhere. They are designed for Microsoft Visual C++ and will not work with the Borland environment.
- Go to a DOS prompt. Run the following commands to have Borland create an
import library from the DLL files you just copied to the
c:\windows\systemdirectory. This way, it will know that the OpenGL commands are implemented elsewhere.
implib opengl32.lib c:\windows\system\opengl32.dll
implib glu32.lib c:\windows\system\glu32.dll
Next, get the GLUT library and install it. You can go to the GLUT homepage and is download glutdlls37beta.zip. Alternatively, you can find it on the Glut for Windows page. Don't get the source, the precompiled binaries are what you want. There is a newer file on the GLUT homepage that has both Win32 and X11 graphics merged. I have not tried this file, but I would imagine it will work the same way.
Unzip that file to
c:\windows\temp\glutdlls and do the
- Copy glut.h to
- Copy glut.dll and glut32.dll to
- Again, do not copy the .lib files anywhere as they are for MSVC++.
- Go to a DOS prompt and type the following:
implib glut.lib c:\windows\system\glut.dll
implib glut32.lib c:\windows\system\glut32.dll
Beginning the Program
Now you are ready to begin developing OpenGL programs in Borland C++. There are two ways to write your programs. If you have multiple files for a larger program, then you will need to create a project. Go to File|New|Project. Type in the path and name of your project. You probably want "Application" for your "Target Type." Select "Win32" for the "Platform" and "Console" for the "Target Model" (unless you are writing a fully Windows program using MFC or the likes for windowing, then select "GUI" for the "Target Model").
The other method is for smaller programs where you only have one source file. In this case, you don't need to start a project. Simply open your source file and compile it. Regardless of which method you choose, you will need to put the following lines in this order in your include section of your code.
It is possible to only include glut.h as it attempts to properly define things for Windows, but you will probably get a few warnings saying that a few definitions are not exactly the same. I would recommend including both. You should probably place them first in your program as windows.h may be useful for other things you may be doing. You do not need to include gl.h or glu.h as glut.h includes them automatically (Or, more correctly, glut.h includes glaux.h which includes both gl.h and glu.h :).
When building your program, Borland may give you a weird error in one of your library files called winmm.lib (or possibly others). If this is the case, I've found that regenerating the library from the DLL solves the problem. To do this, go to DOS and type
implib winmm.lib c:\windows\system\winmm.dll
Exchange the library and DLL name if necessary. Also note that in order for other users to run your OpenGL program, they will also have to have the GLUT DLL's installed. It is not necessary for them to go through this gory detail. Either distribute the glut.dll and glut32.dll with your program or have them download the glutdlls37beta.zip and copy the DLL's to their windows\system directory. Obviously, they will also need to have an OpenGL implementation (either hardware accelerated with their video card or by using Microsoft's software rendering library).
Good luck and happy coding :)
I keep getting the error, "Error: Unresolved external 'glut*'" when I try to build my program.
One cause for this is that Borland is unable to find the glut32.lib file to link with your application. More likely, however, is that your source directory may be somewhere on your hard drive that has a space or long filename in it. The 16-bit components of Borland do not work with files in such a configuration. Move your directory somewhere that follows the DOS 8.3 filename standard.
- During compilation, I keep getting the errors:
gl.h(1135,15):Declaration syntax error
gl.h(1136,15):Multiple declaration for 'WINGDIAPI'
gl.h(1135,15):Earlier declaration of 'WINGDIAPI'or
glaux.h(265,40):Style of function definition is now obsolete
glaux.h(303,53):Undefined symbol 'LPCWSTR'or during linking, I get the error:
"Bad object file record in (path)\glut32.lib near module file offset 0x00000***"
These errors tell you that you have used the incorrect platform and/or model in the "Target Expert." Follow the instructions in step 3 to change this to the correct value.
My program compiles fine, but when running I get the message "You have accidentally used the dummy version of OwlMain."
This error message is caused by using the wrong platform selection in your project file. Open your project. Right click the .exe file in the project window and select "Target Expert." Change the platform to "Win32" and change target model to "Console." Upon successful recompilation, your program should work.
The reason for this error is that you probably selected "GUI" as the target model (or left it as default when creating your project). This is fine if your program is intended to run solely as a windows program (meaning no command line box opening before your application). In this case you need to use the function
void WinMain()instead of
void main()It also seems that you can use
void OwlMain()but I don't know the specifics of using either one as I never have.
- During linking, I get the error:
'C:\BC5\LIB\OPENGL32.LIB' contains invalid OMF record, type 0x21
This means you have used the library from Visual C++ and not recreated a library for Borland from the Windows DLL file. Perform the following:
implib opengl32.lib c:\windows\system\opengl32.dll
- During library conversion, I get the error:
C:\bc5\lib>implib glut32.lib c:\windows\system\glut32.dll
Exception C0000005: Access violation
Module: Impdef.exe start address: 00410000
EAX=...where the other implib's worked fine.