Last active
August 20, 2017 15:33
-
-
Save PeterHajdu/ac909adb2c39d86279f5b8434e467a16 to your computer and use it in GitHub Desktop.
space
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
{-# LANGUAGE OverloadedStrings #-} | |
module Sdl where | |
import Control.Monad (when) | |
import qualified SDL | |
import SDL.Vect | |
import SDL (($=)) | |
import Foreign.C.Types | |
class Graphics g where | |
data Sdl = Sdl SDL.Window SDL.Renderer | |
instance Graphics Sdl | |
screenWidth, screenHeight :: CInt | |
(screenWidth, screenHeight) = (640, 480) | |
setUpSdl :: IO Sdl | |
setUpSdl = do | |
SDL.initialize [SDL.InitVideo] | |
SDL.HintRenderScaleQuality $= SDL.ScaleLinear | |
do renderQuality <- SDL.get SDL.HintRenderScaleQuality | |
when (renderQuality /= SDL.ScaleLinear) $ | |
putStrLn "Warning: Linear texture filtering not enabled!" | |
window <- SDL.createWindow "Space" SDL.defaultWindow {SDL.windowInitialSize = V2 screenWidth screenHeight} | |
SDL.showWindow window | |
renderer <- SDL.createRenderer | |
window | |
(-1) | |
SDL.RendererConfig | |
{ SDL.rendererType = SDL.AcceleratedVSyncRenderer | |
, SDL.rendererTargetTexture = False | |
} | |
return $ Sdl window renderer | |
tearDownSdl :: Sdl -> IO () | |
tearDownSdl (Sdl window _) = do | |
SDL.destroyWindow window | |
SDL.quit | |
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
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Sdl | |
import Control.Exception (bracket) | |
--data Vector a = Vector a a deriving (Show, Eq) | |
--newtype Tile = Tile (Vector Int) | |
--newtype Shape = Shape [Tile] | |
--data Object = Object | |
-- { coordinate :: Vector Integer | |
-- , velocity :: Vector Int | |
-- , orientation :: Float | |
-- , angularVelocity :: Float | |
-- } | |
game :: Graphics e => e -> IO () | |
game engine = undefined | |
main :: IO () | |
main = bracket | |
setUpSdl | |
tearDownSdl | |
game |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment