works now again and we have a renderer

This commit is contained in:
Nicole Dresselhaus 2014-03-26 18:48:59 +01:00
parent 9cd0eacd31
commit 8e0450a712

View File

@ -53,19 +53,25 @@ import qualified Debug.Trace as D (trace)
main :: IO () main :: IO ()
main = do main = do
SDL.withInit [InitVideo, InitAudio, InitEvents, InitTimer] $ do --also: InitNoParachute -> faster, without parachute! SDL.withInit [InitVideo, InitAudio, InitEvents, InitTimer] $ do --also: InitNoParachute -> faster, without parachute!
SDL.withWindow "Pioneers" (SDL.Position 100 100) (Size 1024 600) [WindowOpengl -- we want openGL (window, renderer) <- SDL.createWindowAndRenderer (Size 1024 600) [WindowOpengl -- we want openGL
,WindowShown -- window should be visible ,WindowShown -- window should be visible
,WindowResizable -- and resizable ,WindowResizable -- and resizable
,WindowInputFocus -- focused (=> active) ,WindowInputFocus -- focused (=> active)
,WindowMouseFocus -- Mouse into it ,WindowMouseFocus -- Mouse into it
--,WindowInputGrabbed-- never let go of input (KB/Mouse) --,WindowInputGrabbed-- never let go of input (KB/Mouse)
] $ \window -> do ]
withOpenGL window $ do {- SDL.withWindow "Pioneers" (SDL.Position 100 100) (Size 1024 600) [WindowOpengl -- we want openGL
,WindowShown -- window should be visible
,WindowResizable -- and resizable
,WindowInputFocus -- focused (=> active)
,WindowMouseFocus -- Mouse into it
--,WindowInputGrabbed-- never let go of input (KB/Mouse)
] $ \window -> do-}
mainGlContext <- SDL.glCreateContext window -- withOpenGL window $ do
--TTF.withInit $ do --TTF.withInit $ do
(Size fbWidth fbHeight) <- glGetDrawableSize window (Size fbWidth fbHeight) <- glGetDrawableSize window
initRendering initRendering
renderer <- createRenderer window FirstSupported [Accelerated, TargetTexture]
-- mapybe PresentVSync
--generate map vertices --generate map vertices
(mapBuffer, vert) <- getMapBufferObject (mapBuffer, vert) <- getMapBufferObject
(mapprog, ci, ni, vi, pri, vii, mi, nmi, tli, tlo) <- initMapShader (mapprog, ci, ni, vi, pri, vii, mi, nmi, tli, tlo) <- initMapShader
@ -164,6 +170,8 @@ main = do
putStrLn "init done." putStrLn "init done."
void $ evalRWST (adjustWindow >> run) env state void $ evalRWST (adjustWindow >> run) env state
SDL.glDeleteContext mainGlContext
SDL.destroyRenderer renderer
destroyWindow window destroyWindow window
-- Render-Pipeline -- Render-Pipeline
@ -194,17 +202,17 @@ draw = do
liftIO $ do liftIO $ do
--(vi,GL.UniformLocation proj) <- initShader --(vi,GL.UniformLocation proj) <- initShader
GL.clear [GL.ColorBuffer, GL.DepthBuffer] GL.clear [GL.ColorBuffer, GL.DepthBuffer]
checkError "foo" checkError "clearing buffer"
--set up projection (= copy from state) --set up projection (= copy from state)
with (distribute frust) $ \ptr -> with (distribute frust) $ \ptr ->
glUniformMatrix4fv proj 1 0 (castPtr (ptr :: Ptr (M44 CFloat))) glUniformMatrix4fv proj 1 0 (castPtr (ptr :: Ptr (M44 CFloat)))
checkError "foo" checkError "copy projection"
--set up camera --set up camera
let ! cam = getCam (camX,camY) zDist' xa ya let ! cam = getCam (camX,camY) zDist' xa ya
with (distribute cam) $ \ptr -> with (distribute cam) $ \ptr ->
glUniformMatrix4fv vmat 1 0 (castPtr (ptr :: Ptr (M44 CFloat))) glUniformMatrix4fv vmat 1 0 (castPtr (ptr :: Ptr (M44 CFloat)))
checkError "foo" checkError "copy cam"
--set up normal--Mat transpose((model*camera)^-1) --set up normal--Mat transpose((model*camera)^-1)
let normal = (case inv33 (fmap (^. _xyz) cam ^. _xyz) of let normal = (case inv33 (fmap (^. _xyz) cam ^. _xyz) of