. Un prim exemplu luati dintre exemplele din RedBook

Ati putea incepe cu torul Torus.hs

{- Torus.hs (adapted from torus.c which is (c) Silicon Graphics, Inc.) Copyright (c) Sven Panne 2002-2006 <sven.panne@aedion.de> This file is part of HOpenGL and distributed under a BSD-style license See the file libraries/GLUT/LICENSE This program demonstrates the creation of a display list.-}importData.Char(toLower)importData.IORef(IORef,newIORef)importSystem.Exit(exitWith,ExitCode(ExitSuccess))importGraphics.UI.GLUTimportControl.Monad(forM_)dataState=State{spinX,spinY::IORefGLfloat}makeState::IOStatemakeState=dox<-newIORef0y<-newIORef0return$State{spinX=x,spinY=y}torus::Int->Int->IO()torusnumCnumT=doletstepC=2*pi/fromIntegralnumC::GLfloatstepT=2*pi/fromIntegralnumTforM_[0..numC-1]$\i->renderPrimitiveQuadStrip$forM_[0..numT]$\j->forM_[1,0]$\k->dolets=(fromIntegral((i+k)`mod`numC)+0.5)*stepCt=(fromIntegral(j`mod`numT))*stepTx=(1+0.1*coss)*costy=(1+0.1*coss)*sintz=0.1*sinsvertex(Vertex3xyz)myInit::IODisplayListmyInit=dotheTorus<-defineNewListCompile$torus825shadeModel$=FlatclearColor$=Color40000returntheTorusdisplay::State->DisplayList->DisplayCallbackdisplaystatetheTorus=doclear[ColorBuffer]loadIdentitylookAt(Vertex30010)(Vertex3000)(Vector3010)x<-get(spinXstate)rotatex(Vector3100)y<-get(spinYstate)rotatey(Vector3010)color(Color311(1::GLfloat))callListtheTorusflushreshape::ReshapeCallbackreshapesize@(Sizewh)=doviewport$=(Position00,size)matrixMode$=ProjectionloadIdentityperspective30(fromIntegralw/fromIntegralh)1100matrixMode$=Modelview0incSpin::IORefGLfloat->IO()incSpinspinRef=doletwrapns=max0(s-n)spinRef$~(wrap360.(+30))postRedisplayNothingkeyboard::State->KeyboardMouseCallbackkeyboardstate(Charc)Down__=casetoLowercof'x'->incSpin(spinXstate)'y'->incSpin(spinYstate)'i'->dospinXstate$=0;spinYstate$=0;postRedisplayNothing'\27'->exitWithExitSuccess_->return()keyboard_____=return()main::IO()main=do(progName,_args)<-getArgsAndInitializeinitialDisplayMode$=[SingleBuffered,RGBMode]initialWindowSize$=Size200200createWindowprogNamestate<-makeStatetheTorus<-myInitreshapeCallback$=JustreshapekeyboardMouseCallback$=Just(keyboardstate)displayCallback$=displaystatetheTorusmainLoop