WIP-Commit. DOES NOT WORK.

This commit is contained in:
Nicole Dresselhaus 2014-03-24 08:21:30 +01:00
parent fd38727c65
commit c1e074934e
11 changed files with 109 additions and 24 deletions

View File

@ -0,0 +1,8 @@
#version 330
uniform sampler2D blitTexture;
void main(void)
{
}

6
shaders/ui/vertex.shader Normal file
View File

@ -0,0 +1,6 @@
#version 330
void main()
{
//null-program
}

View File

@ -38,13 +38,15 @@ import Graphics.Rendering.OpenGL.Raw.ARB.TessellationShader
import Map.Map import Map.Map
import Render.Misc (checkError, import Render.Misc (checkError,
createFrustum, getCam, createFrustum, getCam,
curb) curb, tryWithTexture)
import Render.Render (initRendering, import Render.Render (initRendering,
initShader) initMapShader)
import UI.Callbacks import UI.Callbacks
import UI.GUIOverlay import UI.GUIOverlay
import Types import Types
import ThirdParty.Flippers
import qualified Debug.Trace as D (trace) import qualified Debug.Trace as D (trace)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
@ -64,7 +66,7 @@ main = do
initRendering initRendering
--generate map vertices --generate map vertices
(mapBuffer, vert) <- getMapBufferObject (mapBuffer, vert) <- getMapBufferObject
(ci, ni, vi, pri, vii, mi, nmi, tli, tlo) <- initShader (mapprog, ci, ni, vi, pri, vii, mi, nmi, tli, tlo) <- initMapShader
putStrLn "foo" putStrLn "foo"
eventQueue <- newTQueueIO :: IO (TQueue Event) eventQueue <- newTQueueIO :: IO (TQueue Event)
putStrLn "foo" putStrLn "foo"
@ -101,6 +103,7 @@ main = do
, _stateTessellationFactor = 4 , _stateTessellationFactor = 4
, _stateMap = mapBuffer , _stateMap = mapBuffer
, _mapVert = vert , _mapVert = vert
, _mapProgram = mapprog
} }
env = Env env = Env
{ _eventsChan = eventQueue { _eventsChan = eventQueue
@ -150,6 +153,9 @@ main = do
, _game = GameState , _game = GameState
{ {
} }
, _ui = UIState
{
}
} }
putStrLn "init done." putStrLn "init done."
@ -162,6 +168,7 @@ main = do
draw :: Pioneers () draw :: Pioneers ()
draw = do draw = do
state <- get state <- get
env <- ask
let xa = state ^. camera.xAngle let xa = state ^. camera.xAngle
ya = state ^. camera.yAngle ya = state ^. camera.yAngle
(GL.UniformLocation proj) = state ^. gl.glMap.shdrProjMatIndex (GL.UniformLocation proj) = state ^. gl.glMap.shdrProjMatIndex
@ -179,6 +186,8 @@ draw = do
camY = state ^. camera.camPosition.y camY = state ^. camera.camPosition.y
zDist' = state ^. camera.zDist zDist' = state ^. camera.zDist
tessFac = state ^. gl.glMap.stateTessellationFactor tessFac = state ^. gl.glMap.stateTessellationFactor
window = env ^. windowObject
prepareGUI
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]
@ -223,6 +232,12 @@ draw = do
glDrawArrays gl_PATCHES 0 (fromIntegral numVert) glDrawArrays gl_PATCHES 0 (fromIntegral numVert)
checkError "draw" checkError "draw"
{-renderer <- getRenderer (env ^. windowObject)
tryWithTexture
(state ^. gl.hudTexture) --maybe tex
(\tex -> renderCopy renderer tex Nothing Nothing) --function with "hole"
--Nothing == whole source-tex, whole dest-tex
(return ()) --fail-case-}
-- Main game loop -- Main game loop
@ -320,7 +335,7 @@ adjustWindow = do
frust = createFrustum fov near far ratio frust = createFrustum fov near far ratio
liftIO $ glViewport 0 0 (fromIntegral fbWidth) (fromIntegral fbHeight) liftIO $ glViewport 0 0 (fromIntegral fbWidth) (fromIntegral fbHeight)
modify $ camera.frustum .~ frust modify $ camera.frustum .~ frust
hudTex <- liftIO $ do {-hudTex <- liftIO $ do
case state ^. gl.hudTexture of case state ^. gl.hudTexture of
Just tex -> destroyTexture tex Just tex -> destroyTexture tex
_ -> return () _ -> return ()
@ -331,7 +346,7 @@ adjustWindow = do
TextureAccessStreaming -- change occasionally TextureAccessStreaming -- change occasionally
fbWidth -- width fbWidth -- width
fbHeight -- height fbHeight -- height
modify $ gl.hudTexture .~ (Just hudTex) modify $ gl.hudTexture .~ (Just hudTex)-}
processEvents :: Pioneers () processEvents :: Pioneers ()
processEvents = do processEvents = do
@ -344,7 +359,7 @@ processEvents = do
processEvent :: Event -> Pioneers () processEvent :: Event -> Pioneers ()
processEvent e = do processEvent e = do
return () env <- ask
case eventData e of case eventData e of
Window _ winEvent -> Window _ winEvent ->
case winEvent of case winEvent of
@ -363,6 +378,10 @@ processEvent e = do
-- need modifiers? use "keyModifiers key" to get them -- need modifiers? use "keyModifiers key" to get them
let aks = keyboard.arrowsPressed in let aks = keyboard.arrowsPressed in
case keyScancode key of case keyScancode key of
SDL.R ->
liftIO $ do
r <- getRenderer $ env ^. windowObject
putStrLn $ unwords ["Renderer: ",show r]
Escape -> Escape ->
modify $ window.shouldClose .~ True modify $ window.shouldClose .~ True
SDL.Left -> SDL.Left ->

View File

@ -8,6 +8,7 @@ import Graphics.Rendering.OpenGL.GL.StateVar
import Graphics.Rendering.OpenGL.GL.StringQueries import Graphics.Rendering.OpenGL.GL.StringQueries
import Graphics.Rendering.OpenGL.GLU.Errors import Graphics.Rendering.OpenGL.GLU.Errors
import Graphics.Rendering.OpenGL.Raw.Core31 import Graphics.Rendering.OpenGL.Raw.Core31
import Graphics.UI.SDL.Types (Texture)
import System.IO (hPutStrLn, stderr) import System.IO (hPutStrLn, stderr)
import Linear import Linear
import Foreign.C (CFloat) import Foreign.C (CFloat)
@ -116,3 +117,10 @@ curb l h x
| x < l = l | x < l = l
| x > h = h | x > h = h
| otherwise = x | otherwise = x
tryWithTexture :: Maybe Texture -> (Texture -> a) -> a -> a
tryWithTexture t f fail' =
case t of
Just tex -> f tex
_ -> fail'

View File

@ -16,14 +16,20 @@ import Graphics.Rendering.OpenGL.GL.VertexSpec
import Graphics.Rendering.OpenGL.Raw.Core31 import Graphics.Rendering.OpenGL.Raw.Core31
import Render.Misc import Render.Misc
vertexShaderFile :: String mapVertexShaderFile :: String
vertexShaderFile = "shaders/vertex.shader" mapVertexShaderFile = "shaders/map/vertex.shader"
tessControlShaderFile :: String mapTessControlShaderFile :: String
tessControlShaderFile = "shaders/tessControl.shader" mapTessControlShaderFile = "shaders/map/tessControl.shader"
tessEvalShaderFile :: String mapTessEvalShaderFile :: String
tessEvalShaderFile = "shaders/tessEval.shader" mapTessEvalShaderFile = "shaders/map/tessEval.shader"
fragmentShaderFile :: String mapFragmentShaderFile :: String
fragmentShaderFile = "shaders/fragment.shader" mapFragmentShaderFile = "shaders/map/fragment.shader"
uiVertexShaderFile :: String
uiVertexShaderFile = "shaders/ui/vertex.shader"
uiFragmentShaderFile :: String
uiFragmentShaderFile = "shaders/ui/fragment.shader"
initBuffer :: [GLfloat] -> IO BufferObject initBuffer :: [GLfloat] -> IO BufferObject
initBuffer varray = initBuffer varray =
@ -38,8 +44,9 @@ initBuffer varray =
checkError "initBuffer" checkError "initBuffer"
return bufferObject return bufferObject
initShader :: IO ( initMapShader :: IO (
AttribLocation -- ^ color Program -- ^ the GLSL-Program
, AttribLocation -- ^ color
, AttribLocation -- ^ normal , AttribLocation -- ^ normal
, AttribLocation -- ^ vertex , AttribLocation -- ^ vertex
, UniformLocation -- ^ ProjectionMat , UniformLocation -- ^ ProjectionMat
@ -49,17 +56,17 @@ initShader :: IO (
, UniformLocation -- ^ TessLevelInner , UniformLocation -- ^ TessLevelInner
, UniformLocation -- ^ TessLevelOuter , UniformLocation -- ^ TessLevelOuter
) )
initShader = do initMapShader = do
! vertexSource <- B.readFile vertexShaderFile ! vertexSource <- B.readFile mapVertexShaderFile
! tessControlSource <- B.readFile tessControlShaderFile ! tessControlSource <- B.readFile mapTessControlShaderFile
! tessEvalSource <- B.readFile tessEvalShaderFile ! tessEvalSource <- B.readFile mapTessEvalShaderFile
! fragmentSource <- B.readFile fragmentShaderFile ! fragmentSource <- B.readFile mapFragmentShaderFile
vertexShader <- compileShaderSource VertexShader vertexSource vertexShader <- compileShaderSource VertexShader vertexSource
checkError "compile Vertex" checkError "compile Vertex"
tessControlShader <- compileShaderSource TessControlShader tessControlSource tessControlShader <- compileShaderSource TessControlShader tessControlSource
checkError "compile Vertex" checkError "compile TessControl"
tessEvalShader <- compileShaderSource TessEvaluationShader tessEvalSource tessEvalShader <- compileShaderSource TessEvaluationShader tessEvalSource
checkError "compile Vertex" checkError "compile TessEval"
fragmentShader <- compileShaderSource FragmentShader fragmentSource fragmentShader <- compileShaderSource FragmentShader fragmentSource
checkError "compile Frag" checkError "compile Frag"
program <- createProgramUsing [vertexShader, tessControlShader, tessEvalShader, fragmentShader] program <- createProgramUsing [vertexShader, tessControlShader, tessEvalShader, fragmentShader]
@ -104,7 +111,30 @@ initShader = do
putStrLn $ unlines $ ["Indices: ", show (colorIndex, normalIndex, vertexIndex)] putStrLn $ unlines $ ["Indices: ", show (colorIndex, normalIndex, vertexIndex)]
checkError "initShader" checkError "initShader"
return (colorIndex, normalIndex, vertexIndex, projectionMatrixIndex, viewMatrixIndex, modelMatrixIndex, normalMatrixIndex, tessLevelInner, tessLevelOuter) return (program, colorIndex, normalIndex, vertexIndex, projectionMatrixIndex, viewMatrixIndex, modelMatrixIndex, normalMatrixIndex, tessLevelInner, tessLevelOuter)
{-initUIShader :: IO (
Program -- ^ the GLSL-program
, AttribLocation -- ^ the UI-Texture
)
initUIShader = do
! vertexSource <- B.readFile uiVertexShaderFile
! fragmentSource <- B.readFile uiFragmentShaderFile
vertexShader <- compileShaderSource VertexShader vertexSource
checkError "compile Vertex"
fragmentShader <- compileShaderSource FragmentShader fragmentSource
checkError "compile Frag"
program <- createProgramUsing [vertexShader, fragmentShader]
checkError "compile Program"
att <- get (activeAttribs program)
putStrLn $ unlines $ "Attributes: ":map show att
putStrLn $ unlines $ ["Indices: ", show (colorIndex, normalIndex, vertexIndex)]
checkError "initShader"
return (program, )-}
initRendering :: IO () initRendering :: IO ()
initRendering = do initRendering = do

View File

@ -84,6 +84,7 @@ data GLMapState = GLMapState
, _stateTessellationFactor :: !Int , _stateTessellationFactor :: !Int
, _stateMap :: !GL.BufferObject , _stateMap :: !GL.BufferObject
, _mapVert :: !GL.NumArrayIndices , _mapVert :: !GL.NumArrayIndices
, _mapProgram :: !GL.Program
} }
data GLState = GLState data GLState = GLState
@ -91,6 +92,10 @@ data GLState = GLState
, _hudTexture :: Maybe Texture , _hudTexture :: Maybe Texture
} }
data UIState = UIState
{
}
data State = State data State = State
{ _window :: !WindowState { _window :: !WindowState
, _camera :: !CameraState , _camera :: !CameraState
@ -99,6 +104,7 @@ data State = State
, _keyboard :: !KeyboardState , _keyboard :: !KeyboardState
, _gl :: !GLState , _gl :: !GLState
, _game :: !GameState , _game :: !GameState
, _ui :: !UIState
} }
$(makeLenses ''State) $(makeLenses ''State)
@ -113,6 +119,7 @@ $(makeLenses ''CameraState)
$(makeLenses ''WindowState) $(makeLenses ''WindowState)
$(makeLenses ''Position) $(makeLenses ''Position)
$(makeLenses ''Env) $(makeLenses ''Env)
$(makeLenses ''UIState)
type Pioneers = RWST Env () State IO type Pioneers = RWST Env () State IO

View File

@ -24,5 +24,12 @@ alternateClickHandler :: Pixel -> Pioneers ()
alternateClickHandler (Pixel x y) = liftIO $ putStrLn $ unwords ["alternate press on (",show x,",",show y,")"] alternateClickHandler (Pixel x y) = liftIO $ putStrLn $ unwords ["alternate press on (",show x,",",show y,")"]
-- | informs the GUI to prepare a blitting of state ^. gl.hudTexture
--
--TODO: should be done asynchronously at one point.
prepareGUI :: Pioneers ()
prepareGUI = do
return ()
--TODO: Add scroll-Handler, return (Pioneers Bool) to indicate event-bubbling etc. --TODO: Add scroll-Handler, return (Pioneers Bool) to indicate event-bubbling etc.
--TODO: Maybe queues are better? --TODO: Maybe queues are better?