Computer Science Canada

3D Graphics with Haskell

Author:  wtd [ Sat Mar 05, 2005 2:11 pm ]
Post subject:  3D Graphics with Haskell

I know a lot of people here are primarily concerned with graphics, so a quick screenshot, then the code.

Posted Image, might have been reduced in size. Click Image to view fullscreen.

Quote:
module Main where

import Graphics.UI.GLUT
import Graphics.Rendering.OpenGL

main = do
(progName,_) <-getArgsAndInitialize
createAWindow progName
mainLoop

createAWindow windowName = do
createWindow windowName
displayCallback $= displayPoints

displayPoints = do
clear [ColorBuffer]
renderPrimitive Polygon
$ mapM_ (\(x, y, z) -> vertex $ Vertex3 x y z) myPoints

myPoints :: [(GLfloat,GLfloat,GLfloat)]
myPoints =
[(-0.25, 0.25, 0.0)
,(0.75, 0.35, 0.0)
,(0.75, -0.15, 0.0)
,((-0.75), -0.25, 0.0)]


And now, the command required to compile it (Main.hs) using GHC (Glasgow Haskell Compiler) 6.4:

code:
$ ghc --make Main
Chasing modules from: Main
Skipping  Main             ( Main.hs, Main.o )
Linking ...
$ ./a.out


A tutorial is available at:

http://www.tfh-berlin.de/~panitz/hopengl/skript.html#tth_chAp1


: