Free OpenGL Fortran 77 and C++ environment for Windows
Components
The following components were used as a start point for
our kit:
- Borland C++ Builder compiler (free command line tools)
-
GLUT
source for F77 binding headers
- f2c
- fortran to c translator recompiled with BCC
- Fortran binding
for GLUT, GL and GLUT
- No Fortran GL examples were available so I wrote some to verify success
of the idea
Motivation
For teaching graphics with the free tools which can be
given to students for home use without violating the license. Primarily
this kit is intended for Fortran 77 users as there is no simple and
free solution for use on MS Windows. With simple solution I mean the
kit size, ease of installation, ease of use and portability of the executables.
This prerequisites ruled out free tools on Windows such as Cygnus, djgpp,
mingw as they require a lot of unix tools and runtime dlls (portability).
Our executables run with the prerequisite of glut32.dll installed or
placed with executable in the same directory. The use of GLUT is mandatory
for OpenGL window programming abstraction in F77 on Windows.
Installation
- Download
C++ Builder Compiler
command line tools from
Borland
- Download our kit of headers, libraries, binaries,
batch files and F77 examples
- Install BCC command line tools in directory c:\bcc55
- Create c:\bcc55\bin\ilink32.cfg with the link
path switches:
-L"c:\bcc55\lib;c:\bcc55\lib\psdk"
- Create c:\bcc55\bin\bcc32.cfg and add include
directory search
-I"c:\bcc55\include"
-L"c:\bcc55\lib"
- Extract zip contents into c:\. This will overlay c:\bcc55
installation with:
bcc55/bin/f77.bat
bcc55/bin/f2c.exe
bcc55/include/GL/glutf90.h
bcc55/include/GL/fglu.h
bcc55/include/GL/fglut.h
bcc55/include/GL/glut.h
bcc55/include/GL/fgl.h
bcc55/include/f2c.h
bcc55/lib/fopengl32.lib
bcc55/lib/glut32.dll
bcc55/lib/glut32.lib
bcc55/lib/libf77.lib
bcc55/lib/libi77.lib
bcc55/f90gl/gl/cwrap.c
bcc55/f90gl/glu/cwrapglu.c
bcc55/f90gl/glut/cwrapglt.c
bcc55/examples/line.f
bcc55/examples/teapot.f
bcc55/examples/unproject.f
bcc55/examples/tblight.f
bcc55/examples/trackball.c
bcc55/examples/...
- Copy/move glut32.dll from lib into system directory (eg.
c:\windows\system32 or c:\winnt\system32)
- Update Windows search to point to c:\bcc55\bin. For 98/ME update
autoexec.bat, NT/2000 System/Envitonment/Path
Usage
Fortran compiling comes with f77 batch script that eases two
step procedure of converting fortran source into ANSI C and then proceeding
with C compiling and linking into executable. Compilation should be initiated
with Fortran file without extension i.e..:
f77 teapot
Of course, usage of the f77.bat is limited to simple projects/users.
Use it as template for Makefile. To support modular programming several
files can be compiled/linked with one command. The first file should contain
program statement. Precompiled modules should be specified as .obj
files. Example command line:
f77 mainprog module1 module2 module3.c module4.obj module5.obj
Rebuilding sources
f90gl subdirectory is provided for rebuilding fopengl32.lib
from source. No makefile is provided but you can compile fortran
bindery with simple C compile command eg. bcc32 -c cwrap.c
You can build the library with tlib fopengl32.lib +- ..\f90gl\gl\cwrap.obj
in the lib subdir. Maybe someone will properly patch the
files and submitted it to f90gl project
or to me. For rebuilding glut with proper fortran callbacks please
use sources from f90gl. You will need MS Visual C++ for that. As usual
user command implib glut32.lib glut32.dll for building bcc
library extract from .dll.
Bugs
There are differences in internal handling of the string type between
different fortran implementations. f2c is no exception. So if you get
exception violation message from a function this may be the case. Not
many glut routines accept strings. Please send bug reports to
me
an I will see what I can do.
Documentation
For F77 you can use
fortran specification, f2c
and binding for
OpenGL
and
GLUT.
For convenience I collected and converted into PDF
GL
and GLU
fortran binding specification for off-line reading. For GLUT we
use f prefix naming convention as suggested by ARB.
Examples
line.f
You should start with this hello sample with minimal code needed for
GLUT windowing application. It consist of two compilation units: Subroutine
display and main program named line. Every program
unit needs include files at the beginning of the code. Usually this is
GL/fglut.h for main and additionally GL/fgl.h and
GL/fglu.h for callback routines. Default callback routines are assumed
except for display. Window area is (-1,-1) (1,1) and anamorphical resize.
teapot.f
Adds keyboard event demo and glut predefined object. Note that every
callback function needs to be specified with external otherwise
this name will be treated as variable. I strongly suggest to use implicit
none for every program unit.
unproject.f
Mouse events are captured and then viewport coordinates are back projected
into world coordinates which are then drawn as polyline. This is 2D demo
as the z is assumed.
cube-f.f
Shaded cube with their sides marked with stoked font text.
tblight.f
Lighting demo and quaternion rotation example with external C source routine
and builtin Fortran binding.
Compile this demo with: f77 tblight trackball.c
mm.f
MadMax highway animation of 5 vehicles.
Leon Kos
LECAD
University of Ljubljana
Created: March 2002