Skip to content

Instantly share code, notes, and snippets.

@alphaneet
Created January 28, 2012 08:51
Show Gist options
  • Save alphaneet/1693562 to your computer and use it in GitHub Desktop.
Save alphaneet/1693562 to your computer and use it in GitHub Desktop.
haskell で GLUT 使って hello work
import System.Exit ( exitWith, ExitCode(ExitSuccess) )
-- http://hackage.haskell.org/package/GLUT
import Graphics.UI.GLUT
intToFloat :: Int -> Float
intToFloat n = read (show n)::Float
--scrx :: Int -> Float
scrx :: Fractional a => a -> a
scrx x = 2 * x / 320.0 - 1.0
scry y = 1.0 - 2 * y / 400.0
color3i r g b = color (Color3 (r/255) (g/255) (b/255 :: GLfloat))
display :: DisplayCallback
display = do
clear [ColorBuffer]
color3i 255 255 255
preservingMatrix $ do
translate (Vector3 (scrx 100) (scry 100) 0 ::Vector3 Float)
scale 0.0007 0.0005 (1.0 :: Double)
renderString Roman "hello work"
putStrLn "display"
swapBuffers
keyboardMouse :: KeyboardMouseCallback
keyboardMouse (Char 'q') _ _ _ = exitWith ExitSuccess
keyboardMouse (Char 'a') _ _ _ = putStrLn("key")
keyboardMouse (MouseButton LeftButton) _ _ _ = putStrLn("mouse")
screenWidth = 320
screenHeight = 400
screenLeft = 100
screenTop = 100
main :: IO()
main = do
getArgsAndInitialize
initialDisplayMode $= [ DoubleBuffered, RGBMode ]
initialWindowSize $= Size screenWidth screenHeight
initialWindowPosition $= Position screenLeft screenTop
createWindow "hoge"
displayCallback $= display
keyboardMouseCallback $= Just keyboardMouse
mainLoop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment