Guest User

HOpenGL test

a guest
Jun 9th, 2011
1,272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {-
  2.    Light.hs (adapted from light.c which is (c) Silicon Graphics, Inc.)
  3.    Copyright (c) Sven Panne 2002-2005 <[email protected]>
  4.    This file is part of HOpenGL and distributed under a BSD-style license
  5.    See the file libraries/GLUT/LICENSE
  6.  
  7.    This program demonstrates the use of the OpenGL lighting model. A sphere
  8.    is drawn using a grey material characteristic. A single light source
  9.    illuminates the object.
  10. -}
  11.  
  12. import System.Exit ( exitWith, ExitCode(ExitSuccess) )
  13. import Graphics.UI.GLUT
  14.  
  15. myInit :: IO ()
  16. myInit = do
  17.    clearColor $= Color4 0 0 0 0
  18.    shadeModel $= Smooth
  19.  
  20.    materialSpecular Front $= Color4 1 1 1 1
  21.    materialShininess Front $= 50
  22.    position (Light 0) $= Vertex4 1 1 1 0
  23.  
  24.    lighting $= Enabled
  25.    light (Light 0) $= Enabled
  26.    depthFunc $= Just Less
  27.  
  28. display :: DisplayCallback
  29. display = do
  30.    clear [ ColorBuffer, DepthBuffer ]
  31.    renderObject Solid (Sphere' 1 20 16)
  32.   flush
  33.  
  34. reshape :: ReshapeCallback
  35. reshape size@(Size w h) = do
  36.   viewport $= (Position 0 0, size)
  37.   matrixMode $= Projection
  38.   loadIdentity
  39.   let wf = fromIntegral w
  40.       hf = fromIntegral h
  41.   if w <= h
  42.      then ortho (-1.5) 1.5 (-1.5 * hf/wf) (1.5 * hf/wf) (-10) 10
  43.      else ortho (-1.5 * wf/hf) (1.5 * wf/hf) (-1.5) 1.5 (-10) 10
  44.   matrixMode $= Modelview 0
  45.   loadIdentity
  46.  
  47. keyboard :: KeyboardMouseCallback
  48. keyboard (Char '\27') Down _ _ = exitWith ExitSuccess
  49. keyboard _            _    _ _ = return ()
  50.  
  51. main :: IO ()
  52. main = do
  53.   (progName, _args) <- getArgsAndInitialize
  54.   initialDisplayMode $= [ SingleBuffered, RGBMode, WithDepthBuffer ]
  55.   initialWindowSize $= Size 500 500
  56.   initialWindowPosition $= Position 100 100
  57.   createWindow progName
  58.   myInit
  59.   displayCallback $= display
  60.   reshapeCallback $= Just reshape
  61.   keyboardMouseCallback $= Just keyboard
  62.   mainLoop
Advertisement
Add Comment
Please, Sign In to add comment