Created
January 28, 2012 08:51
-
-
Save alphaneet/1693562 to your computer and use it in GitHub Desktop.
haskell で GLUT 使って hello work
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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