2014-02-05 16:33:32 +01:00
|
|
|
{-# LANGUAGE BangPatterns, DoAndIfThenElse #-}
|
2014-01-20 14:12:02 +01:00
|
|
|
module Main where
|
2014-01-03 03:01:54 +01:00
|
|
|
|
2014-04-15 17:03:54 +02:00
|
|
|
import Graphics.Rendering.OpenGL.GL.Texturing.Specification (texImage2D,TextureTarget2D(Texture2D))
|
2014-04-04 11:15:00 +02:00
|
|
|
import Graphics.Rendering.OpenGL.GL.PixelRectangles.ColorTable (PixelInternalFormat(..))
|
|
|
|
import Graphics.Rendering.OpenGL.GL.Texturing.Objects (textureBinding)
|
2014-04-15 17:03:54 +02:00
|
|
|
import Graphics.Rendering.OpenGL.GL.Texturing.Parameters (TextureFilter(..),textureFilter)
|
2014-04-04 11:15:00 +02:00
|
|
|
|
2014-01-20 23:18:07 +01:00
|
|
|
-- Monad-foo and higher functional stuff
|
2014-04-15 17:03:54 +02:00
|
|
|
import Control.Monad (unless, when, join)
|
2014-04-07 17:32:13 +02:00
|
|
|
import Control.Arrow ((***))
|
2014-01-20 19:28:02 +01:00
|
|
|
|
|
|
|
-- data consistency/conversion
|
|
|
|
import Control.Concurrent (threadDelay)
|
2014-02-04 14:11:16 +01:00
|
|
|
import Control.Concurrent.STM (TQueue,
|
|
|
|
newTQueueIO)
|
|
|
|
|
2014-04-15 17:03:54 +02:00
|
|
|
import Control.Monad.RWS.Strict (ask, evalRWST, get, liftIO, modify)
|
2014-04-15 08:59:53 +02:00
|
|
|
import Data.Functor ((<$>))
|
|
|
|
import Data.Monoid (mappend)
|
2014-01-20 19:28:02 +01:00
|
|
|
|
2014-01-20 14:12:02 +01:00
|
|
|
-- FFI
|
2014-04-07 17:32:13 +02:00
|
|
|
import Foreign.Marshal.Array (pokeArray)
|
|
|
|
import Foreign.Marshal.Alloc (allocaBytes)
|
2014-01-20 14:12:02 +01:00
|
|
|
|
|
|
|
-- Math
|
2014-03-05 14:42:26 +01:00
|
|
|
import Control.Lens ((^.), (.~), (%~))
|
2014-01-05 20:23:22 +01:00
|
|
|
|
2014-01-20 14:12:02 +01:00
|
|
|
-- GUI
|
2014-05-10 20:22:49 +02:00
|
|
|
import qualified Graphics.UI.SDL as SDL
|
2014-01-20 14:12:02 +01:00
|
|
|
|
|
|
|
-- Render
|
2014-01-05 20:23:22 +01:00
|
|
|
import qualified Graphics.Rendering.OpenGL.GL as GL
|
|
|
|
import Graphics.Rendering.OpenGL.Raw.Core31
|
2014-03-17 17:04:30 +01:00
|
|
|
import Data.Time (getCurrentTime, diffUTCTime)
|
2014-01-05 20:23:22 +01:00
|
|
|
|
2014-01-20 14:12:02 +01:00
|
|
|
-- Our modules
|
2014-04-21 19:46:24 +02:00
|
|
|
import Render.Misc (checkError, createFrustum, curb,
|
2014-04-05 23:09:57 +02:00
|
|
|
genColorData)
|
2014-01-05 20:23:22 +01:00
|
|
|
import Render.Render (initRendering,
|
2014-04-04 11:15:00 +02:00
|
|
|
initMapShader,
|
2014-04-21 20:25:47 +02:00
|
|
|
initHud, render)
|
2014-04-21 19:46:24 +02:00
|
|
|
import Render.Types
|
2014-02-05 16:33:32 +01:00
|
|
|
import UI.Callbacks
|
2014-04-21 20:25:47 +02:00
|
|
|
import Map.Graphics
|
2014-02-05 16:33:32 +01:00
|
|
|
import Types
|
2014-04-09 20:04:06 +02:00
|
|
|
import Importer.IQM.Parser
|
2014-04-25 21:21:19 +02:00
|
|
|
--import Data.Attoparsec.Char8 (parseTest)
|
|
|
|
--import qualified Data.ByteString as B
|
2014-01-03 03:01:54 +01:00
|
|
|
|
2014-04-15 17:03:54 +02:00
|
|
|
-- import qualified Debug.Trace as D (trace)
|
2014-01-20 19:28:02 +01:00
|
|
|
|
2014-01-20 16:11:34 +01:00
|
|
|
--------------------------------------------------------------------------------
|
2014-04-09 20:04:06 +02:00
|
|
|
|
2014-04-25 21:21:19 +02:00
|
|
|
testParser :: String -> IO ()
|
|
|
|
testParser a = putStrLn . show =<< parseIQM a
|
|
|
|
{-do
|
2014-05-01 20:31:15 +02:00
|
|
|
f <- B.readFile a
|
|
|
|
putStrLn "reading in:"
|
|
|
|
putStrLn $ show f
|
|
|
|
putStrLn "parsed:"
|
|
|
|
parseTest parseIQM f-}
|
2014-04-09 20:04:06 +02:00
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
2013-12-22 23:29:11 +01:00
|
|
|
main :: IO ()
|
2014-04-15 17:03:54 +02:00
|
|
|
main =
|
2014-05-10 20:22:49 +02:00
|
|
|
SDL.withInit [SDL.InitVideo, SDL.InitAudio, SDL.InitEvents, SDL.InitTimer] $ --also: InitNoParachute -> faster, without parachute!
|
|
|
|
SDL.withWindow "Pioneers" (SDL.Position 100 100) (SDL.Size 1024 600) [SDL.WindowOpengl -- we want openGL
|
|
|
|
,SDL.WindowShown -- window should be visible
|
|
|
|
,SDL.WindowResizable -- and resizable
|
|
|
|
,SDL.WindowInputFocus -- focused (=> active)
|
|
|
|
,SDL.WindowMouseFocus -- Mouse into it
|
2014-03-26 18:48:59 +01:00
|
|
|
--,WindowInputGrabbed-- never let go of input (KB/Mouse)
|
2014-04-15 17:03:54 +02:00
|
|
|
] $ \window' -> do
|
2014-05-10 20:22:49 +02:00
|
|
|
SDL.withOpenGL window' $ do
|
2014-04-15 17:03:54 +02:00
|
|
|
|
2014-04-05 15:53:49 +02:00
|
|
|
--Create Renderbuffer & Framebuffer
|
|
|
|
-- We will render to this buffer to copy the result into textures
|
|
|
|
renderBuffer <- GL.genObjectName
|
|
|
|
frameBuffer <- GL.genObjectName
|
|
|
|
GL.bindFramebuffer GL.Framebuffer GL.$= frameBuffer
|
|
|
|
GL.bindRenderbuffer GL.Renderbuffer GL.$= renderBuffer
|
2014-04-15 17:03:54 +02:00
|
|
|
|
2014-05-10 20:22:49 +02:00
|
|
|
(SDL.Size fbWidth fbHeight) <- SDL.glGetDrawableSize window'
|
2014-01-20 16:11:34 +01:00
|
|
|
initRendering
|
|
|
|
--generate map vertices
|
2014-04-24 14:21:25 +02:00
|
|
|
glMap' <- initMapShader 4 =<< getMapBufferObject
|
2014-05-10 20:22:49 +02:00
|
|
|
eventQueue <- newTQueueIO :: IO (TQueue SDL.Event)
|
2014-01-20 19:28:02 +01:00
|
|
|
now <- getCurrentTime
|
2014-02-23 13:32:20 +01:00
|
|
|
--font <- TTF.openFont "fonts/ttf-04B_03B_/04B_03B_.TTF" 10
|
|
|
|
--TTF.setFontStyle font TTFNormal
|
|
|
|
--TTF.setFontHinting font TTFHNormal
|
2014-01-20 16:11:34 +01:00
|
|
|
|
2014-04-15 17:03:54 +02:00
|
|
|
glHud' <- initHud
|
|
|
|
let zDistClosest' = 1
|
|
|
|
zDistFarthest' = zDistClosest' + 50
|
2014-02-04 14:11:16 +01:00
|
|
|
--TODO: Move near/far/fov to state for runtime-changability & central storage
|
2014-01-20 16:11:34 +01:00
|
|
|
fov = 90 --field of view
|
|
|
|
near = 1 --near plane
|
2014-04-05 23:27:52 +02:00
|
|
|
far = 500 --far plane
|
2014-01-20 16:11:34 +01:00
|
|
|
ratio = fromIntegral fbWidth / fromIntegral fbHeight
|
|
|
|
frust = createFrustum fov near far ratio
|
2014-04-26 19:16:53 +02:00
|
|
|
(guiMap, guiRoots) = createGUI
|
2014-01-20 23:18:07 +01:00
|
|
|
aks = ArrowKeyState {
|
2014-02-23 13:32:20 +01:00
|
|
|
_up = False
|
|
|
|
, _down = False
|
|
|
|
, _left = False
|
|
|
|
, _right = False
|
2014-01-20 23:18:07 +01:00
|
|
|
}
|
2014-01-20 16:11:34 +01:00
|
|
|
env = Env
|
2014-02-23 13:32:20 +01:00
|
|
|
{ _eventsChan = eventQueue
|
2014-04-15 17:03:54 +02:00
|
|
|
, _windowObject = window'
|
|
|
|
, _zDistClosest = zDistClosest'
|
|
|
|
, _zDistFarthest = zDistFarthest'
|
2014-01-20 16:11:34 +01:00
|
|
|
}
|
|
|
|
state = State
|
2014-02-23 13:32:20 +01:00
|
|
|
{ _window = WindowState
|
|
|
|
{ _width = fbWidth
|
|
|
|
, _height = fbHeight
|
|
|
|
, _shouldClose = False
|
|
|
|
}
|
|
|
|
, _camera = CameraState
|
|
|
|
{ _xAngle = pi/6
|
|
|
|
, _yAngle = pi/2
|
|
|
|
, _zDist = 10
|
|
|
|
, _frustum = frust
|
2014-04-21 19:46:24 +02:00
|
|
|
, _camObject = createFlatCam 25 25
|
2014-02-23 13:32:20 +01:00
|
|
|
}
|
|
|
|
, _io = IOState
|
|
|
|
{ _clock = now
|
2014-05-07 09:51:35 +02:00
|
|
|
, _tessClockFactor = 0
|
2014-02-23 13:32:20 +01:00
|
|
|
}
|
|
|
|
, _mouse = MouseState
|
|
|
|
{ _isDown = False
|
|
|
|
, _isDragging = False
|
|
|
|
, _dragStartX = 0
|
|
|
|
, _dragStartY = 0
|
|
|
|
, _dragStartXAngle = 0
|
|
|
|
, _dragStartYAngle = 0
|
2014-03-05 14:42:26 +01:00
|
|
|
, _mousePosition = Types.Position
|
2014-04-07 17:32:13 +02:00
|
|
|
{ Types.__x = 5
|
|
|
|
, Types.__y = 5
|
2014-02-23 13:32:20 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
, _keyboard = KeyboardState
|
|
|
|
{ _arrowsPressed = aks
|
|
|
|
}
|
|
|
|
, _gl = GLState
|
2014-04-15 17:03:54 +02:00
|
|
|
{ _glMap = glMap'
|
|
|
|
, _glHud = glHud'
|
2014-04-05 15:53:49 +02:00
|
|
|
, _glRenderbuffer = renderBuffer
|
|
|
|
, _glFramebuffer = frameBuffer
|
2014-02-23 13:32:20 +01:00
|
|
|
}
|
|
|
|
, _game = GameState
|
|
|
|
{
|
|
|
|
}
|
2014-03-24 08:21:30 +01:00
|
|
|
, _ui = UIState
|
2014-04-05 23:09:57 +02:00
|
|
|
{ _uiHasChanged = True
|
2014-04-26 19:16:53 +02:00
|
|
|
, _uiMap = guiMap
|
|
|
|
, _uiRoots = guiRoots
|
2014-03-24 08:21:30 +01:00
|
|
|
}
|
2014-01-20 16:11:34 +01:00
|
|
|
}
|
2014-01-20 19:28:02 +01:00
|
|
|
|
|
|
|
putStrLn "init done."
|
2014-04-15 08:59:53 +02:00
|
|
|
uncurry mappend <$> evalRWST (adjustWindow >> run) env state
|
2014-04-15 17:03:54 +02:00
|
|
|
putStrLn "shutdown complete."
|
|
|
|
|
2014-04-04 11:18:42 +02:00
|
|
|
--SDL.glDeleteContext mainGlContext
|
|
|
|
--SDL.destroyRenderer renderer
|
|
|
|
--destroyWindow window
|
2014-01-20 16:11:34 +01:00
|
|
|
|
|
|
|
-- Main game loop
|
|
|
|
|
|
|
|
run :: Pioneers ()
|
|
|
|
run = do
|
2014-03-05 14:42:26 +01:00
|
|
|
env <- ask
|
2014-01-20 16:11:34 +01:00
|
|
|
|
|
|
|
-- draw Scene
|
2014-01-20 20:04:21 +01:00
|
|
|
draw
|
2014-05-10 20:22:49 +02:00
|
|
|
liftIO $ SDL.glSwapWindow (env ^. windowObject)
|
2014-01-20 16:11:34 +01:00
|
|
|
-- getEvents & process
|
|
|
|
processEvents
|
|
|
|
|
|
|
|
-- update State
|
|
|
|
|
|
|
|
state <- get
|
|
|
|
-- change in camera-angle
|
2014-03-05 14:42:26 +01:00
|
|
|
when (state ^. mouse.isDragging) $ do
|
|
|
|
let sodx = state ^. mouse.dragStartX
|
|
|
|
sody = state ^. mouse.dragStartY
|
|
|
|
sodxa = state ^. mouse.dragStartXAngle
|
|
|
|
sodya = state ^. mouse.dragStartYAngle
|
2014-04-07 17:32:13 +02:00
|
|
|
x' = state ^. mouse.mousePosition._x
|
|
|
|
y' = state ^. mouse.mousePosition._y
|
2014-03-05 14:42:26 +01:00
|
|
|
myrot = (x' - sodx) / 2
|
|
|
|
mxrot = (y' - sody) / 2
|
2014-01-20 16:11:34 +01:00
|
|
|
newXAngle = curb (pi/12) (0.45*pi) newXAngle'
|
|
|
|
newXAngle' = sodxa + mxrot/100
|
|
|
|
newYAngle
|
|
|
|
| newYAngle' > pi = newYAngle' - 2 * pi
|
|
|
|
| newYAngle' < (-pi) = newYAngle' + 2 * pi
|
|
|
|
| otherwise = newYAngle'
|
|
|
|
newYAngle' = sodya + myrot/100
|
2014-04-15 17:03:54 +02:00
|
|
|
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ ((camera.xAngle) .~ newXAngle)
|
|
|
|
. ((camera.yAngle) .~ newYAngle)
|
2014-01-20 16:11:34 +01:00
|
|
|
|
|
|
|
-- get cursor-keys - if pressed
|
|
|
|
--TODO: Add sin/cos from stateYAngle
|
2014-02-04 14:11:16 +01:00
|
|
|
(kxrot, kyrot) <- fmap (join (***) fromIntegral) getArrowMovement
|
2014-04-15 17:03:54 +02:00
|
|
|
let
|
2014-03-05 14:42:26 +01:00
|
|
|
multc = cos $ state ^. camera.yAngle
|
|
|
|
mults = sin $ state ^. camera.yAngle
|
|
|
|
modx x' = x' - 0.2 * kxrot * multc
|
|
|
|
- 0.2 * kyrot * mults
|
2014-04-05 15:53:49 +02:00
|
|
|
mody y' = y' + 0.2 * kxrot * mults
|
2014-03-05 14:42:26 +01:00
|
|
|
- 0.2 * kyrot * multc
|
2014-04-21 19:46:24 +02:00
|
|
|
modify $ camera.camObject %~ (\c -> moveBy c (\(x,y) -> (modx x,mody y)))
|
2014-03-05 14:42:26 +01:00
|
|
|
|
2014-01-20 16:11:34 +01:00
|
|
|
{-
|
|
|
|
--modify the state with all that happened in mt time.
|
|
|
|
mt <- liftIO GLFW.getTime
|
|
|
|
modify $ \s -> s
|
|
|
|
{
|
|
|
|
}
|
|
|
|
-}
|
2014-03-05 14:42:26 +01:00
|
|
|
|
2014-05-11 21:12:53 +02:00
|
|
|
(mt,tc,sleepAmount,frameTime) <- liftIO $ do
|
2014-05-05 08:11:33 +02:00
|
|
|
let double = fromRational.toRational :: (Real a) => a -> Double
|
2014-05-11 21:12:53 +02:00
|
|
|
targetFramerate = 60.0
|
2014-05-05 08:11:33 +02:00
|
|
|
targetFrametime = 1.0/targetFramerate
|
|
|
|
targetFrametimeμs = targetFrametime * 1000000.0
|
2014-01-20 19:28:02 +01:00
|
|
|
now <- getCurrentTime
|
2014-05-07 09:51:35 +02:00
|
|
|
let diff = diffUTCTime now (state ^. io.clock) -- get time-diffs
|
|
|
|
title = unwords ["Pioneers @ ",show ((round . double $ 1.0/diff)::Int),"fps"]
|
2014-05-11 21:12:53 +02:00
|
|
|
ddiff = double diff
|
2014-05-10 20:22:49 +02:00
|
|
|
SDL.setWindowTitle (env ^. windowObject) title
|
2014-05-05 08:11:33 +02:00
|
|
|
let sleepAmount = floor ((targetFrametime - double diff)*1000000) :: Int -- get time until next frame in microseconds
|
2014-05-07 09:51:35 +02:00
|
|
|
clockFactor = (state ^. io.tessClockFactor)
|
2014-05-05 08:11:33 +02:00
|
|
|
tessChange
|
2014-05-11 21:12:53 +02:00
|
|
|
| (clockFactor < (75*targetFrametime)) && (state ^. gl.glMap.stateTessellationFactor < 5) = ((+)1 :: Int -> Int)
|
|
|
|
-- > last 100 frames had > 25% leftover (on avg.)
|
|
|
|
| (clockFactor > (110*targetFrametime)) && (state ^. gl.glMap.stateTessellationFactor > 1) = (flip (-) 1 :: Int -> Int)
|
|
|
|
-- > last 100 frames had < 90% of target-fps
|
2014-05-05 08:11:33 +02:00
|
|
|
| otherwise = ((+)0 :: Int -> Int) -- 0ms > x > 10% -> keep settings
|
|
|
|
when (sleepAmount > 0) $ threadDelay sleepAmount
|
2014-05-11 21:12:53 +02:00
|
|
|
now' <- getCurrentTime
|
|
|
|
return (now',tessChange,sleepAmount,ddiff)
|
2014-01-20 19:28:02 +01:00
|
|
|
-- set state with new clock-time
|
2014-05-12 11:30:29 +02:00
|
|
|
--liftIO $ putStrLn $ unwords ["clockFactor:",show (state ^. io.tessClockFactor),"\ttc:", show (tc (state ^. gl.glMap.stateTessellationFactor)),"\tsleep ",show frameTime,"ms"]
|
2014-05-05 08:11:33 +02:00
|
|
|
modify $ (io.clock .~ mt)
|
|
|
|
. (gl.glMap.stateTessellationFactor %~ tc)
|
2014-05-11 21:12:53 +02:00
|
|
|
. (io.tessClockFactor %~ (((+) frameTime).((*) 0.99)))
|
2014-05-07 09:51:35 +02:00
|
|
|
-- liftIO $ putStrLn $ concat $ ["TessFactor at: ",show (state ^. gl.glMap.stateTessellationFactor), " - slept for ",show sleepAmount, "μs."]
|
2014-04-15 17:03:54 +02:00
|
|
|
shouldClose' <- return $ state ^. window.shouldClose
|
|
|
|
unless shouldClose' run
|
2014-01-20 16:11:34 +01:00
|
|
|
|
2014-04-21 20:25:47 +02:00
|
|
|
draw :: Pioneers ()
|
|
|
|
draw = do
|
|
|
|
state <- get
|
|
|
|
when (state ^. ui . uiHasChanged) prepareGUI
|
|
|
|
render
|
|
|
|
|
2014-01-20 23:18:07 +01:00
|
|
|
getArrowMovement :: Pioneers (Int, Int)
|
|
|
|
getArrowMovement = do
|
|
|
|
state <- get
|
2014-04-15 17:03:54 +02:00
|
|
|
aks <- return $ state ^. (keyboard.arrowsPressed)
|
|
|
|
let
|
2014-01-20 23:18:07 +01:00
|
|
|
horz = left' + right'
|
|
|
|
vert = up'+down'
|
2014-03-05 14:42:26 +01:00
|
|
|
left' = if aks ^. left then -1 else 0
|
|
|
|
right' = if aks ^. right then 1 else 0
|
|
|
|
up' = if aks ^. up then -1 else 0
|
|
|
|
down' = if aks ^. down then 1 else 0
|
2014-01-20 23:18:07 +01:00
|
|
|
return (horz,vert)
|
|
|
|
|
2014-01-20 16:11:34 +01:00
|
|
|
adjustWindow :: Pioneers ()
|
|
|
|
adjustWindow = do
|
|
|
|
state <- get
|
2014-03-05 14:42:26 +01:00
|
|
|
let fbWidth = state ^. window.width
|
|
|
|
fbHeight = state ^. window.height
|
2014-01-20 16:11:34 +01:00
|
|
|
fov = 90 --field of view
|
|
|
|
near = 1 --near plane
|
|
|
|
far = 100 --far plane
|
|
|
|
ratio = fromIntegral fbWidth / fromIntegral fbHeight
|
|
|
|
frust = createFrustum fov near far ratio
|
|
|
|
liftIO $ glViewport 0 0 (fromIntegral fbWidth) (fromIntegral fbHeight)
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ camera.frustum .~ frust
|
2014-04-05 15:53:49 +02:00
|
|
|
rb <- liftIO $ do
|
|
|
|
-- bind ints to CInt for lateron.
|
|
|
|
let fbCWidth = (fromInteger.toInteger) fbWidth
|
|
|
|
fbCHeight = (fromInteger.toInteger) fbHeight
|
|
|
|
-- free old renderbuffer & create new (reuse is NOT advised!)
|
|
|
|
GL.deleteObjectName (state ^. gl.glRenderbuffer)
|
|
|
|
renderBuffer <- GL.genObjectName
|
|
|
|
GL.bindRenderbuffer GL.Renderbuffer GL.$= renderBuffer
|
|
|
|
GL.renderbufferStorage
|
2014-04-15 17:03:54 +02:00
|
|
|
GL.Renderbuffer -- use the only available renderbuffer
|
2014-04-05 15:53:49 +02:00
|
|
|
-- - must be this constant.
|
|
|
|
GL.DepthComponent' -- 32-bit float-rgba-color
|
|
|
|
(GL.RenderbufferSize fbCWidth fbCHeight) -- size of buffer
|
|
|
|
|
|
|
|
|
|
|
|
let hudtexid = state ^. gl.glHud.hudTexture
|
2014-04-24 14:21:25 +02:00
|
|
|
maptexid = state ^. gl.glMap.renderedMapTexture
|
2014-05-13 10:40:35 +02:00
|
|
|
smaptexid = state ^. gl.glMap.shadowMapTexture
|
2014-04-04 11:15:00 +02:00
|
|
|
allocaBytes (fbWidth*fbHeight*4) $ \ptr -> do
|
2014-04-05 22:02:48 +02:00
|
|
|
--default to ugly pink to see if
|
|
|
|
--somethings go wrong.
|
2014-04-05 23:09:57 +02:00
|
|
|
let imData = genColorData (fbWidth*fbHeight) [255,0,255,0]
|
2014-04-04 11:15:00 +02:00
|
|
|
--putStrLn $ show imData
|
|
|
|
pokeArray ptr imData
|
2014-04-05 15:53:49 +02:00
|
|
|
-- HUD
|
|
|
|
textureBinding Texture2D GL.$= Just hudtexid
|
|
|
|
textureFilter Texture2D GL.$= ((Linear', Nothing), Linear')
|
|
|
|
texImage2D Texture2D GL.NoProxy 0 RGBA8 (GL.TextureSize2D fbCWidth fbCHeight) 0
|
|
|
|
(GL.PixelData GL.RGBA GL.UnsignedByte ptr)
|
|
|
|
-- MAP
|
|
|
|
textureBinding Texture2D GL.$= Just maptexid
|
|
|
|
textureFilter Texture2D GL.$= ((Linear', Nothing), Linear')
|
|
|
|
texImage2D Texture2D GL.NoProxy 0 RGBA8 (GL.TextureSize2D fbCWidth fbCHeight) 0
|
2014-04-04 11:15:00 +02:00
|
|
|
(GL.PixelData GL.RGBA GL.UnsignedByte ptr)
|
2014-05-13 10:40:35 +02:00
|
|
|
allocaBytes (2048*2048) $ \ptr -> do
|
|
|
|
let smapdata = genColorData (2048*2048) [0]
|
|
|
|
pokeArray ptr smapdata
|
|
|
|
textureBinding Texture2D GL.$= Just smaptexid
|
|
|
|
textureFilter Texture2D GL.$= ((Nearest,Nothing), Nearest)
|
|
|
|
texImage2D Texture2D GL.NoProxy 0 GL.DepthComponent16 (GL.TextureSize2D 2048 2048) 0
|
|
|
|
(GL.PixelData GL.DepthComponent GL.UnsignedByte ptr)
|
2014-04-04 11:15:00 +02:00
|
|
|
checkError "setting up HUD-Tex"
|
2014-04-05 15:53:49 +02:00
|
|
|
return renderBuffer
|
|
|
|
modify $ gl.glRenderbuffer .~ rb
|
2014-04-05 23:09:57 +02:00
|
|
|
modify $ ui.uiHasChanged .~ True
|
2014-01-20 16:11:34 +01:00
|
|
|
|
|
|
|
processEvents :: Pioneers ()
|
|
|
|
processEvents = do
|
2014-05-10 20:22:49 +02:00
|
|
|
me <- liftIO SDL.pollEvent
|
2014-01-20 19:28:02 +01:00
|
|
|
case me of
|
|
|
|
Just e -> do
|
|
|
|
processEvent e
|
|
|
|
processEvents
|
|
|
|
Nothing -> return ()
|
|
|
|
|
2014-05-10 20:22:49 +02:00
|
|
|
processEvent :: SDL.Event -> Pioneers ()
|
2014-01-20 19:28:02 +01:00
|
|
|
processEvent e = do
|
2014-05-01 20:31:15 +02:00
|
|
|
eventCallback e
|
|
|
|
-- env <- ask
|
|
|
|
case SDL.eventData e of
|
|
|
|
SDL.Window _ winEvent -> -- windowID event
|
|
|
|
case winEvent of
|
|
|
|
SDL.Closing ->
|
2014-03-05 14:42:26 +01:00
|
|
|
modify $ window.shouldClose .~ True
|
2014-05-10 20:22:49 +02:00
|
|
|
SDL.Resized {SDL.windowResizedTo=size} -> do
|
2014-05-01 20:31:15 +02:00
|
|
|
modify $ (window . width .~ SDL.sizeWidth size)
|
|
|
|
. (window . height .~ SDL.sizeHeight size)
|
|
|
|
adjustWindow
|
|
|
|
SDL.SizeChanged ->
|
|
|
|
adjustWindow
|
|
|
|
_ -> return ()
|
|
|
|
_ -> return ()
|