SML# - Resources/ProgrammingExamples/GLUT Diff

  • Added parts are displayed like this.
  • Deleted parts are displayed like this.

Using [[SML# interpoperability|FeatureInteroperability]]
you can easily call various C packages.
This page shows a simple example code to call OpenGL.

The [[glut sample|smlsharp:examples/glut/doc/]]
(in sample/glut directory of the source distribution)
uses OpenGL and GLUT to show a sample 3D animation.


OpenGL and GLUT requires doule data manipuation, and call back
functions of many arguments.
In SML#, you can call various C functions of various functionalities including those taking callback functions by just declaraing their types, as shown below.

val glMaterialfv =
     DynamicLink.dlsym (libgl, "glMaterialfv")
     : _import (word, word, float * float * float * float) -> unit

val gluLookAt =
     DynamicLink.dlsym (libglu, "gluLookAt")
     : _import (real, real, real, real, real, real, real, real, real) -> unit

val glutDisplayFunc =
     DynamicLink.dlsym (libglut, "glutDisplayFunc")
     : _import (()->unit) -> unit

!!How to run the sample.

This uses an experimental [[CConfig library|smlsharp:lib/CConfig/doc/api/]] to locate
library functions, but it is not perfect and you may need to set
environment variables to tell the program the install location of
libraries such as OpenGL.
Below is some suggestion.


env CPPFLAGS=-I/usr/X11R6/include LDFLAGS=-L/usr/X11R6/lib smlsharp cube.sml

Mac OS X:

env LDD='otool -L' smlsharp cube.sml


env CPPFLAGS=-I/usr/X11R6/include LDFLAGS=-L/usr/X11R6/lib \
     LIBNAME_SUFFIX=.dll LDD=cygcheck ARCSEP='\' smlsharp cube.sml

!!! MinGW on Windows

You can try to run it on MinGW on Windows.
The Windows system appears to have OpenGL (perhaps in opengl32.dll,
You can also get GLUT library from [[this site|]].
You probably need to hand modify the code
Good luck.