{-
   TexProx.hs (adapted from texprox.c which is (c) Silicon Graphics, Inc)
   This file is part of HOpenGL - a binding of OpenGL and GLUT for Haskell.
   Copyright (C) 2000  Sven Panne <Sven.Panne@informatik.uni-muenchen.de>

   The brief program illustrates use of texture proxies.
   This program only prints out some messages about whether
   certain size textures are supported and then exits.

   NOTE: InternalFormat is not an instance of Show (which would be a hack),
   so it is not printed. Furthermore, GL_TEXTURE_COMPONENTS is used for
   compatibility reasons only in texprox.c, we use GL_INTERNAL_FORMAT instead.
-}

import System.Exit ( exitWith, ExitCode(ExitSuccess) )

import GL
import Graphics.UI.GLUT

myInit :: IO ()
myInit = do
   texImage2D ProxyTexture2d 0 Rgba8 64 64 0 (PixelDescriptor GL.Rgba UnsignedByte nullPtr)
   proxyComponents1 <- get (ProxyTexture2d, 0::GLint, VarTextureInternalFormat)
   putStrLn ("proxy allocation " ++ if proxyComponents1 == Rgba8 then "succeeded" else "failed")

   texImage2D ProxyTexture2d 0 Rgba16 2048 2048 0 (PixelDescriptor GL.Rgba UnsignedShort nullPtr)
   proxyComponents2 <- get (ProxyTexture2d, 0::GLint, VarTextureInternalFormat)
   putStrLn ("proxy allocation " ++ if proxyComponents2 == Rgba16 then "succeeded" else "failed")

display :: DisplayCallback
display = exitWith ExitSuccess

reshape :: ReshapeCallback
reshape (WindowSize w h) = do
   viewport (0, 0) (fromIntegral w, fromIntegral h)
   matrixMode Projection
   loadIdentity

main :: IO ()
main = do
   (progName, _args) <- getArgsAndInitialize
   setInitialDisplayMode [ Single, RGB ]
   setInitialWindowSize (WindowSize 500 500)
   setInitialWindowPosition (WindowPosition 100 100)
   createWindow progName
   myInit
   setDisplayCallback display
   setReshapeCallback (Just reshape)
   mainLoop
