Created
September 27, 2019 14:04
-
-
Save Lifelovinglight/28eb961b40fb5a7b75e6c850d58c169a to your computer and use it in GitHub Desktop.
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
-- Requires installation of SDL2 https://github.com/haskell-game/sdl2 | |
-- and possibly GLUT https://hackage.haskell.org/package/GLUT | |
-- Using graphics code from https://wiki.haskell.org/OpenGLTutorial1 | |
module Main (main) where | |
import Control.Monad | |
import Linear | |
import Data.StateVar | |
import Foreign.C.Types (CInt) | |
import qualified SDL | |
import Control.Monad.Loops | |
import qualified Graphics.Rendering.OpenGL as OpenGL | |
import Data.Text (Text) | |
import qualified Data.Text as Text | |
myVertices :: [OpenGL.Vertex3 OpenGL.GLfloat] | |
myVertices = [ OpenGL.Vertex3 (sin (2*pi*k/12)) (cos (2*pi*k/12)) 0 | k <- [1..12] ] | |
screenWidth, screenHeight :: CInt | |
(screenWidth, screenHeight) = (640, 480) | |
myWindowConfig :: SDL.WindowConfig | |
myWindowConfig = SDL.defaultWindow { SDL.windowInitialSize = V2 screenWidth screenHeight | |
, SDL.windowGraphicsContext = SDL.OpenGLContext SDL.defaultOpenGL } | |
main :: IO () | |
main = do | |
SDL.initialize [SDL.InitVideo] | |
SDL.HintRenderScaleQuality $= SDL.ScaleLinear | |
window <- SDL.createWindow (Text.pack "SDL / OpenGL Example") myWindowConfig | |
SDL.showWindow window | |
SDL.glCreateContext window | |
iterateWhile not $ | |
OpenGL.clear [OpenGL.ColorBuffer] | |
>> OpenGL.renderPrimitive OpenGL.Points (mapM_ OpenGL.vertex myVertices) | |
>> OpenGL.flush | |
>> SDL.glSwapWindow window | |
>> any ((== SDL.QuitEvent) . SDL.eventPayload) <$> unfoldM SDL.pollEvent | |
SDL.destroyWindow window | |
SDL.quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment