I developed the direct G95 fortran bindings to OpenGL+GLUT libraries. This is much faster and uses much less memory than does the traditional import library method, expecially when linking large libraries or applications. This version implements the interface for OpenGL 1.2+, GLU 1.2+, GLUT 3.7, FreeGlut/OpenGlut and several extensions. It supports several Unix workstations and Windows 98/NT/2000/Me/XP.
The G95 bindings for OpenGL are an alternative to the older Fortran 90 bindings. This increases the similarity between the Fortran and C interfaces to OpenGL.
I got the Dr. William F. Mitchell examples and remade it for G95. The examples fortran source files and Fortran interface modules you can download here:
| Unix Fortran sources | Win32 Fortran sources |
|---|---|
| Unix OpenGL module | Windows OpenGL module |
Details
call glutinit(1,loc('thePgm'//char(0)))
character(100), pointer :: str
..............................
str=>glGetString(GL_VERSION)
l=min(len(str),index(str,char(0)))
print *, 'OpenGL version is ',str(1:l)
loc to get address.Example
call glVertexPointer( 2, GL_FLOAT, 0, loc(P) )where
P is a real array of vertices with coordinates x,y.
integer(C_INTPTR_T). Example
integer(C_INTPTR_T) :: nurb
nurb = gluNewNurbsRenderer()
See details in molehill.f90
__glutInitWithExit (old glut 3.7).
Use g_glutInitWithExit instead.
subroutine motion(x, y) bind(c)
integer(GLint), intent(in), value :: x, y
....................................
end subroutine motion
For compiling you need in file opengl.mod.
You have to get the OpenGLu.f03 file for Unix32/64 platform or
OpenGLw.f03 for Windows platform. You have to create opengl.mod
with command line
g95 OpenGLx.f03 -S
For Windows platform you need in FGlut32.dll. In principle, this is
the same as FreeGlut/OpenGlut, but I remade CALLBACKs for stdcall calling convention.
If you have MinGW gcc, you can make it very easy:
freeglut_internal.h the strings
typedef void (* FGCto
typedef void (__stdcall * FGC
MakeFGlutDll.bat.
FGlut32.dll here.
For compiling on Unix32/64 platform you may use the next command lines
g95 -fno-underscoring %1.f90 -o %1 -Wl,/usr/lib/libGL.so,/usr/lib/libGLU.so,/usr/lib/libglut.so.3 g95 -fno-underscoring %1.f90 -o %1 -Wl,/usr/lib64/libGL.so,/usr/lib64/libGLU.so,/usr/lib64/libglut.so.3where
%1 is file name.
For compiling on Win32 platform you may use the next command line
g95.exe -mrtd -fno-underscoring %1.f90 -o %1 -Wl,%windir%/system32/opengl32.dll,%windir%/system32/glu32.dll,%windir%/system32/fglut32.dllwhere
%1 is file name.