Compiler notes for F03GL (and Orient)

These notes relate to the F03GL interface modules between Fortran and OpenGL, and are relevant to any Fortran program that uses OpenGL graphics. However, notwithstanding the datestamp at the bottom of this page, they were written in January 2011 and are seriously out of date. Any Fortran 2003 or later compiler running on a modern 64-bit computer ought to be able to cope.

Nag nagfor compiler

We have tested the Fortran modules with the Nag f95 and nagfor compilers. They work by default to the Fortran95 standard, and generate a great many warning messages about Fortran2003 extensions. Some but not all of these can be avoided by specifying the –f2003 compiler flag.

There have been difficulties under Windows NT (32-bit) because of differences between naming conventions used by the compilers and the OpenGL libraries. In the case of the Nag compilers, these difficulties can be overcome by replacing BIND(C,NAME="...") in the f03gl interfaces by BIND(C,NAME="__stdcall ..."). Such difficulties are not expected to arise with 64-bit versions of Windows.


Recent versions of the gfortran compiler (version 4.4.0 and 4.5.0) work. Note that string arguments must be converted explicitly to null-terminated C character arrays, using the CString function. See the example programs for usage.

Portland pgfortran

Version 10.9 of the pgfortran compiler handles C-interoperability, but some of the test files throw up errors. We have not yet been able to establish whether these are due to bugs in the compiler or mistakes in our code.


Versions 11.1.059 and later of the Intel ifort compiler compile and run the test programs successfully, though it was necessary to rename one of the menu_handler routines in plotfunc.f90, even though they are in different modules and declared private.

Windows Visual Studio

As with the Nag compilers, there have been difficulties under Windows NT (32-bit) because of differences between naming conventions used by the compilers and the OpenGL libraries. The following procedure has been suggested by Gregory Lantoine, whose help is gratefully acknowledged.

In IVF, it is not possible to use BIND(C,NAME="...") for STDCALL routines. Instead, you must remove the BIND(C,NAME="...") attribute and then add a directive of the form: !DEC$ ATTRIBUTES STDCALL, REFERENCE, DECORATE, ALIAS:"glClear" :: glClear in the interface body, for each gl, glu and glut routine.

For the glut routines with callbacks as arguments, I changed the syntax of the interface a little bit. I use bind(C) for the calling convention of the callbacks:

subroutine glutDisplayFunc(fun)  
  !DEC$ ATTRIBUTES STDCALL, REFERENCE, DECORATE, ALIAS:"glutDisplayFunc" :: glutDisplayFunc  
      subroutine fun() bind(c)  
      end subroutine fun  
    end interface  
  end subroutine glutDisplayFunc  
end interface  

In the callback declarations in the main program, we must also specify bind(C).

Valid XHTML 1.0 Transitional