-- A simple example demonstrating how to get info about GL/GLU
-- and some buffer/implementation dependent values.
-- Sven Panne 2000.   mailto:Sven.Panne@informatik.uni-muenchen.de

import GL
import GLU
import Graphics.UI.GLUT

main :: IO ()
main = do
   -- Necessary for GL initialization
   (progName, _args) <- getArgsAndInitialize
   createWindow progName
   setDisplayCallback (return ())

   putStrLn "---------- GL info -----------"
   putStr "Vendor:       "; putStrLn =<< get VarVendor
   putStr "Renderer:     "; putStrLn =<< get VarRenderer
   printVersion                      =<< get GL.VarVersion
   printExtensions                   =<< get GL.VarExtensions

   putStrLn "\n---------- GLU info ----------"
   printVersion                      =<< GLU.getVersion
   printExtensions                   =<< GLU.getExtensions

   putStrLn "\n---------- buffer info ----------"
   sequence_ [ do flag <- get v
                  putStrLn (msg ++ ": " ++ if flag then "yes" else "no")
             | (msg, v) <- [
                ("RGBA mode       ", VarRgbaMode    ),
                ("color index mode", VarIndexMode   ),
                ("double buffer   ", VarDoublebuffer),
                ("stereo          ", VarStereo      ) ] ]

   putStrLn "\n---------- pixel depths ----------"
   sequence_ [ do bits <- get v
                  putStrLn (msg ++ ": " ++ show (bits :: GLint))
             | (msg, v) <- [
                ("color(red)        ", VarRedBits       ),
                ("color(green)      ", VarGreenBits     ),
                ("color(blue)       ", VarBlueBits      ),
                ("color(alpha)      ", VarAlphaBits     ),
                ("index             ", VarIndexBits     ),
                ("depth             ", VarDepthBits     ),
                ("stencil           ", VarStencilBits   ),
                ("accumulator(red)  ", VarAccumRedBits  ),
                ("accumulator(green)", VarAccumGreenBits),
                ("accumulator(blue) ", VarAccumBlueBits ),
                ("accumulator(alpha)", VarAccumAlphaBits) ] ]

printVersion :: VersionInfo -> IO ()
printVersion (VersionInfo versionNo vendor) =
   putStrLn ("Version:      " ++ versionNo ++ " " ++ vendor)

printExtensions :: ExtensionsInfo -> IO ()
printExtensions (ExtensionsInfo exts) = do
   putStrLn "Extensions:"
   mapM_ (\ext -> putStrLn ("   " ++ ext)) exts
