Skip to content

Instantly share code, notes, and snippets.

@ishiy1993
Created November 25, 2015 00:21
Show Gist options
  • Save ishiy1993/84fca525063d265f02e3 to your computer and use it in GitHub Desktop.
Save ishiy1993/84fca525063d265f02e3 to your computer and use it in GitHub Desktop.
HaskellでOpenGL(GLUT)を使って、ウィンドウのサイズを変えても描画されている図形の大きさが変わらないようにする。
import Graphics.UI.GLUT
display :: DisplayCallback
display = do
clear [ColorBuffer]
color (Color3 0 0 0 :: Color3 GLdouble)
renderPrimitive Polygon $ mapM_ vertex2d [
Vertex2 (-0.9) (-0.9)
, Vertex2 0.9 (-0.9)
, Vertex2 0.9 0.9
, Vertex2 (-0.9) 0.9
]
flush
where
vertex2d = vertex :: Vertex2 GLdouble -> IO ()
resize :: Size -> IO ()
resize s@(Size w h) = do
viewport $= (Position 0 0,s)
loadIdentity
ortho (-w') (w') (-h') (h') (-1.0) (1.0)
where
w' = realToFrac w / 200.0
h' = realToFrac h / 200.0
main :: IO ()
main = do
getArgsAndInitialize
initialDisplayMode $= [RGBAMode]
createWindow "Sample"
clearColor $= Color4 1 1 1 1
displayCallback $= display
reshapeCallback $= Just resize
mainLoop
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment