Skip to content

Instantly share code, notes, and snippets.

@PeterHajdu
Last active August 20, 2017 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PeterHajdu/ac909adb2c39d86279f5b8434e467a16 to your computer and use it in GitHub Desktop.
Save PeterHajdu/ac909adb2c39d86279f5b8434e467a16 to your computer and use it in GitHub Desktop.
space
{-# 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
{-# 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