Print

Print


Hello,

I am attaching an open-source use-as-you-please example of using the C 
Interop features of Fortran 2003 in order to directly call OpenGL from 
Fortran. There is not a single wrapper and the only C code used is the 
trivial attached code OpenGL_c.c used to extract the values of 
constants from the OpenGL header files. These are then pasted as 
PARAMETER in the Fortran module.

I did not try to provide a full interface to OpenGL. I am hoping some 
Perl (or similar language) expert will come up with scripts to 
automatically generate the interfaces to save me from typing. Also for 
extracting constants from header files and maybe even type definitions. 
I don't think it can be fully automated, but most of it can.

The example uses GLUT in order to manipulate windows. Two extra routines 
not in classical GLUT, which I added to the freeglut and openglut 
libraries [glutGet(Set)WindowData] are used however I provided 
replacement stubs at the end of OpenGL.f90 for those using classical 
GLUT. On my Linux box it compiles with:

f95 OpenGL.f90 -o OpenGL.x -lglut -lGLU -lGL -L/usr/X11R6/lib -lXmu -lXi 
-lX11

and works fine. It is nothing fancy, just a silly sphere whose radius 
changes "randomly" in a Markov-chain fashion. But it works!

Best,
Aleksandar