haskelloids/src/Init.hs

73 lines
1.7 KiB
Haskell
Raw Normal View History

2017-12-16 10:55:30 +00:00
module Init where
2017-12-16 18:06:36 +00:00
import Affection as A
2017-12-16 10:55:30 +00:00
import SDL (($=))
import qualified SDL
import qualified Data.Set as S
import Data.Maybe
2017-12-16 18:06:36 +00:00
import Control.Monad (when)
import Control.Monad.IO.Class (liftIO)
2017-12-16 10:55:30 +00:00
import System.Random
2017-12-16 18:06:36 +00:00
import NanoVG hiding (V2(..))
import Linear
2017-12-16 10:55:30 +00:00
-- Internal imports
import Types
load :: IO UserData
load = do
2017-12-16 18:06:36 +00:00
liftIO $ logIO A.Debug "loading state"
liftIO $ logIO A.Debug "creating NanoVG context"
2017-12-16 10:55:30 +00:00
nvgCtx <- createGL3 (S.fromList [Antialias, StencilStrokes])
2017-12-16 18:06:36 +00:00
liftIO $ logIO A.Debug "load ship image"
mshipImage <- createImage nvgCtx (FileName "assets/ship.svg") 0
when (isNothing mshipImage) $
2017-12-16 10:55:30 +00:00
logIO Error "Failed loading image assets"
return UserData
{ ship = Ship
{ sPos = V2 400 300
, sVel = V2 0 0
, sRot = 0
2017-12-16 18:06:36 +00:00
, sImg = fromJust mshipImage
2017-12-16 10:55:30 +00:00
}
, haskelloids = []
, wonlost = Nothing
, state = Menu
, fade = FadeIn 1
, nano = nvgCtx
}
-- _ <- SDL.setMouseLocationMode SDL.RelativeLocation
-- GL.depthFunc $= ust GL.Less
-- pane <- GL.genObjectName
-- GL.BindVertexArrayObject $= Just pane
-- verts <- GL.genObejctName
-- let vertCoord =
-- [ (-1), (-1), 0
-- , 1 , (-1), 0
-- , (-1), 1 , 0
-- , 1 , 1 , 0
-- , (-1), 1 , 0
-- , 1 , (-1), 0
-- ]
-- withArray vertCoord $ \ptr
-- GL.bufferData GL.ArrayBuffer $=
-- ( fromIntegral $ length vertCoord * 3 * sizeOf (0 :: Double)
-- , ptr
-- , GL.StaticDraw
-- )
-- GL.vertexAttribPointer (GL.AttribLocation 0) $=
-- ( GL.ToFloat
-- , GL.VertexArrayDescriptor 4 GL.Float 0 (plusPtr nullPtr 0)
-- )
-- GL.vertexAttribArray (GL.AttribLocation 0) $= GL.Enabled