Sie sind auf Seite 1von 4

DEV-C++ and OPENGL (for MS Windows 98/NT/2000/XP)

(Satya Baboolal, Computer Science, UKZN, 2006)

This guide explains how to install and run the Dev-C++ IDE-compiler supplied by
Bloodshed Software. It also explains how to install and run with it, the Silicon
Graphics interface OPENGL and the related GNU windowing toolkit GLUT.
Amazingly, all these products are available as free downloads, and may be freely used
and distributed under their individual licence agreements.

Dev-C++
This is available as a free download from the site: http://www.bloodshed.net. This
compiler suite is based on the GNU gcc and g++ compilers and uses the so-called
Minimalist Windows (“MinGw”) version of it.
The currently available versions are 4.0 (complete) and 4.9.5.0 (beta 5: using the
MinGW port of the GCC compiler version 2.95.3-6) and 4.9.9.2 (beta 5: MinGW of
GCC 3.4.2). I am presently using 4.9.5.0. So download the file devcpp4950 (also
available on our website) which is a self-extracting MS-Win32 executable file.
Installation:
1. Put your download into any directory you want.
2. Double-click on it from explorer (one way) and you will get its set up screen,
prompting for an installation directory.
3. Choose an installation directory e.g. c:\Dev-Cpp (default)
4. Then choose ‘next’ to extract to it. A windows program group will be created
to allow you to run it.

Running DevC++
This is a complete compiler-linker-makefile-project-builder IDE, so many options are
available, including command-line mode (from a DOS prompt). Below are two ways
of using the IDE in windows. For c programs it’s better to switch-off the all the
options in tools -> compiler options (in particular ANSI, CYGWIN) except if
required, the linker options.
1. To compile, link and run stand alone files: Choose “new – source file” and
then you are in a single file edit mode. Type in your code as usual and then
either click on the compile (mult-color square on 2nd left line) to compile. The
run button is the next square etc. Alternatively click on the “EXECUTE” tab
and choose “compile”, “run”, “build”, “debug” etc. For old source files choose
“open file or project”, select the file you want and proceed as above.
2. Projects: In many situations, especially for the creation of windows
applications one is required to define a “project”. This is basically a virtual
bag for containing various related files that eventually culminate in an
application, such as a windows .exe or .dll file. On this system a project file
has a .dev extension and resides separately from its related files (.cpp, .exe,
.rc,..), all in some working directory e.g. CPROGS. Alternatively, on other
systems projects are held as sub-directories in the working directory.

To create a new project, choose ‘new’ then ‘project’. You are then prompted
for the type of project (console application, windows application, static
library, dll library, empty project). If you want to do some processing with
simple console I/O choose the first. Choosing a windows application will
generate for you a main windows program which has some standard windows
controls built-in. An empty project will have no files – so you can add your
own. However, unless you set up the linker switches manually, you may find
that the intended windows application will fail to link to the WIN32 API dlls.
So, for windows applications it’s better to choose this project type in the first
place.

When choosing a windows application, you are prompted for the project
name, supply e.g. test1. This will create test1.dev in the working directory. At
the same time it creates and loads a file main.cpp which is your main
windows application program. When you run the compiler, the system
prompts for the name of your main source file, so choosing test1 will rename
main.cpp to test1.cpp and then compile the project. The linker is called by
default and depending on your project choices, the application file test1.exe
will be created, if all goes well. This can be run from the IDE or independently
from outside it, in the usual way. A project choice also generates a related
resource file. This file (extension .rc) containing “resource scripts” for
allocating various “resources” that are required by the project, one such being
for example, the type of ICON for the .exe file. For most purposes you do not
have to worry about this file, so simply live with the default one for now.

If you choose an empty project you can add an existing source (.cpp) file to it
by selecting from the Project tab, “add unit” or “add to project” etc. Selecting
“new unit” will allow you to type in a new source file.

OPENGL
This is Silicon Graphics’ graphical interface available from various download sites, in
particular: http://www.sgi.com

OpenGL is a low-level interface that directly addresses the hardware for fast graphics,
and by-passes the MS windows API. The current MS windows version is release 2
(ver. 1.2.1) and comes as a single self-extracting download application file opengl2.
Download and install this into some directory (default is c:\OGLSDK ). This will also
install the opengl32.dll file into your windows run-time environment, which is
usually needed by applications using OpenGL. Many compiler systems now include
OpenGL, as does DevC++, so all that is usually required is that the opengl32.dll file
is made available.

To make use of OpenGL study the user guide in the OGLSDK directory or look at
some DevC++ examples in the DevC++ directory. Whilst windows programming
together with OpenGL can be used to write graphical applications, a convenient
windowing GNU toolkit, GLUT is available to take away much of the drudgery.

GLUT
Glut is a convenient tool that allows you to declare windows and sub-windows in
which various graphical components can be running. It makes use of calls to OpenGL
so this must be available either separately, or in your compiler suite (like it is in
DevC++). For MS windows this package is available as the version 3.7.6 file
glut32.zip, which when expanded results in glut32.lib, glut32.dll, glut32.def, glut.h
and some documentation. These should be located in some directory like GLUT and
the windows system PATH environment variable should then be set to c:\GLUT. The
latter is necessary in order to make available the file glut32.dll, required in many
applications. Alternatively, if all your graphics source code is in some directory like
c:\openglprogs, simply copying glut32.dll into it will work too. In addition, it is
advisable to copy (if not already there) the header file glut.h into the “includes”
directory of the compiler. For example, this is already in c:\DevC++\include.

DevC++ setup for OpenGL and Glut


To get DevC++ to run these, we have to:
1. Employ the include directives in your .cpp file
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include <gl/glut.h>
2. Employ the corresponding linker switches in the compiler-options tab:
-lopengl32 –lglu32 –lglaux –lglut32 --lcomctl32

or, in place of 2 above,


3. Set for only the project that requires it the corresponding linker optional files
opengl.lib glu32.lib glut.lib glut32.lib
I prefer 2. above, so I don’t have to keep changing it for different projects.
Technical note:
GLUT 3.7 tries to avoid using <windows.h> in order to prevent possible name
space pollution, but Win32's <GL/gl.h> needs APIENTRY and WINGDIAPI to
be defined properly. Thus, whilst this header can be avoided in MS
Win98/NT/2000/XP, we found that the header file is required for windows
applications under the MS Win XP Tablet PC edition. So, it’s safer to include it,
otherwise GLUT fails to link.

Now, DevC++ programs calling OpenGL and Glut should compile, link and run.

WARNING: Silicon Graphics requires that their copyright (terms and conditions)
file be included with any application you distribute – so take care. Bloodshed and
GNU have similar requirement.

For more on windows programming see later.

Recent note: using DevC++ 4.9.9.2 (supports latest ANSI/ISO 98 standard)


Easy installation: copy entire install directory to your own e.g. c:\dev-cpp_4992
• Marry the OpenGl and glut libs with it – i.e. copy all the opengl, glut ...h
files to the new ...\include
• Copy the old ...glut32.dll, opengl.dll to the new ...\bin
• Copy the old ..\lib\opengl32, glu32, glut32, lib files to the new ..\lib
Run DevCpp and set the linker options under the compiler tab to include
the following in the command line:
-lopengl32 -lglu32 -lglaux -lglut32 -lcomctl32
• Set the config file under the environment tab to write to another config file
if you wish.
• After the above, should be ready to run.
To install the complete expanded directory onto your system without the above build
process, see the InstallingDevCpp.doc on our website.

Das könnte Ihnen auch gefallen