[HOpenGL] How to compile a hopengl program?

Sven Panne Sven.Panne@informatik.uni-muenchen.de
Mon, 21 Apr 2003 15:58:18 +0200


Bas van Dijk wrote:
 > I built GHC from sources using --enable-hopengl at configuration
 > time. [...]

In that case "-package GLUT" is OK. The GLUT package depends on the
OpenGL package (cf. the output of "ghc-pkg --show-package=GLUT"), so
there is no need for an explicit "-package OpenGL". The reason for the
new package names is a cleaner separation of the rendering part
(GL/GLU in package "OpenGL") and the UI part (GLUT in package "GLUT").
The error you get is caused by the fact that the new API in CVS uses
hierarchical modules, while the examples on the web pages are for the
old modules. Another basic difference is that the new API is modeled
around the notion of "state variables"

    http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/libraries/OpenGL/Graphics/Rendering/OpenGL/GL/StateVar.hs?rev=1.1&content-type=text/x-cvsweb-markup

which mirrors the OpenGL state machine very closely and gives a
unified view of getters and setters, e.g. the current viewport has the
type

    viewport :: StateVar (Position, Size)

So you can set the viewport with

    viewport $= (Position 10 10, Size 20 20)

and retrieve the current viewport with

    (Position x y, Size w h) <- get viewport

OpenGL state which can only be queried has a different type, e.g.

    maxViewportDims :: GettableStateVar Size

which allows

    mvd <- get maxViewportDims

but catches the following error at compile-time:

    maxViewportDims $= Size 30 40

Some examples with the new API:

    http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/libraries/GLUT/examples/RedBook/Hello.hs?rev=1.4&content-type=text/x-cvsweb-markup
    http://cvs.haskell.org/cgi-bin/cvsweb.cgi/fptools/libraries/GLUT/examples/RedBook/Smooth.hs?rev=1.3&content-type=text/x-cvsweb-markup

After this small digression, here my advice: If you want to use
Haskell + OpenGL *now*, you should probably use HOpenGL 1.04 from
http://haskell.org/HOpenGL, not the stuff from CVS. Switching to the
new API in the future will be relatively easy because there are no
subtle semantic changes, mostly syntax.

Cheers,
    S.