File: Pitfall14.hs

package info (click to toggle)
haskell-glut 2.1.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 1,936 kB
  • ctags: 25
  • sloc: haskell: 10,092; sh: 2,811; ansic: 53; makefile: 2
file content (33 lines) | stat: -rw-r--r-- 1,110 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
{-
   Pitfall14
   Copyright (c) Sven Panne 2002-2005 <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 pitfall 14 (Careful Enabling Color Material)
   of Mark Kilgard's "16 Common OpenGL Pitfalls", see:
   http://www.opengl.org/resources/features/KilgardTechniques/oglpitfall/
-}

import Control.Monad ( unless )
import System.Exit ( exitFailure )
import Graphics.UI.GLUT

main :: IO ()
main = do
   (progName, _args) <- getArgsAndInitialize
   initialDisplayMode $= [ SingleBuffered, RGBMode ]
   createWindow progName

   currentColor $= Color4 1 1 1 1
   materialAmbient Front $= Color4 0.1 0.1 0.1 1
   -- re-get to avoid any rounding issues
   mafBefore <- get (materialAmbient Front)

   colorMaterial $= Just (Front, Diffuse)
   mafAfter <- get (materialAmbient Front)
   unless (mafBefore == mafAfter) $ do
      putStrLn "ERROR: The ambient material property changed!"
      putStrLn ("   before: " ++ show mafBefore)
      putStrLn ("   after : " ++ show mafAfter)
      exitFailure