Refactor text rendering
This commit is contained in:
@@ -2,13 +2,13 @@
|
|||||||
out vec4 FragColor;
|
out vec4 FragColor;
|
||||||
|
|
||||||
in vec4 gColor;
|
in vec4 gColor;
|
||||||
in vec2 gTex;
|
in vec2 gTexCoord;
|
||||||
|
|
||||||
uniform sampler2D aTexture;
|
uniform sampler2D aTexture;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
FragColor = texture(aTexture, gTex) * gColor;
|
FragColor = texture(aTexture, vec2 (gTexCoord.x * 0.0078125, gTexCoord.y)) * gColor;
|
||||||
// FragColor = texture(aTexture, vTexCoord);
|
// FragColor = texture(aTexture, vTexCoord);
|
||||||
// FragColor = gColor;
|
// FragColor = gColor;
|
||||||
// FragColor = vec4 (1,1,1,1);
|
// FragColor = vec4 (1,1,1,1);
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
#version 430 core
|
#version 430 core
|
||||||
layout (location = 0) in vec3 aPos;
|
layout (location = 0) in vec3 aPos;
|
||||||
layout (location = 1) in vec4 aColor;
|
layout (location = 1) in vec4 aColor;
|
||||||
layout (location = 2) in vec3 aTexCoord;
|
layout (location = 2) in vec2 aTexCoord;
|
||||||
|
|
||||||
uniform mat4 worldMat;
|
uniform mat4 worldMat;
|
||||||
|
|
||||||
out vec4 vColor;
|
out vec4 gColor;
|
||||||
out vec3 vTexCoord;
|
out vec2 gTexCoord;
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gl_Position = vec4(aPos, 1.0);
|
gl_Position = vec4(aPos, 1.0);
|
||||||
vColor = aColor;
|
gColor = aColor;
|
||||||
vTexCoord = aTexCoord;
|
gTexCoord = aTexCoord;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -396,9 +396,9 @@ longGun = defaultGun
|
|||||||
, _itIdentity = LongGun
|
, _itIdentity = LongGun
|
||||||
, _wpMaxAmmo = 1
|
, _wpMaxAmmo = 1
|
||||||
, _wpLoadedAmmo = 1
|
, _wpLoadedAmmo = 1
|
||||||
, _wpReloadTime = 80
|
, _wpReloadTime = 100
|
||||||
, _wpReloadState = 0
|
, _wpReloadState = 0
|
||||||
, _wpReloadType = PassiveReload sineRaisePitchOneSecSound
|
, _wpReloadType = PassiveReload skwareFadeTwoSecSound
|
||||||
, _itUseRate = 100
|
, _itUseRate = 100
|
||||||
, _itUseTime = 0
|
, _itUseTime = 0
|
||||||
, _itUse = shootWithSound (fromIntegral longGunSound)
|
, _itUse = shootWithSound (fromIntegral longGunSound)
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ makeLaserScope
|
|||||||
-> Float -- ^ Fraction of red/green
|
-> Float -- ^ Fraction of red/green
|
||||||
-> Particle
|
-> Particle
|
||||||
makeLaserScope p ep relFrac = Particle
|
makeLaserScope p ep relFrac = Particle
|
||||||
{_ptDraw = const $ onLayer PtLayer $ pictures
|
{_ptDraw = const $ setLayer 1 $ onLayer PtLayer $ pictures
|
||||||
[lineAlphaThick 0.5 0.5
|
[lineAlphaThick 0.5 0.5
|
||||||
,lineAlphaThick 0.2 1.5
|
,lineAlphaThick 0.2 1.5
|
||||||
,lineAlphaThick 0.1 2
|
,lineAlphaThick 0.1 2
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import Dodge.Picture.Layer.Data
|
|||||||
import Picture
|
import Picture
|
||||||
{- | Uses a layer to set the depth. -}
|
{- | Uses a layer to set the depth. -}
|
||||||
onLayer :: Layer -> Picture -> Picture
|
onLayer :: Layer -> Picture -> Picture
|
||||||
onLayer l = setDepth $ 1 - fromIntegral (levLayer l) / 100
|
onLayer l = setDepth $ (1 - fromIntegral (levLayer l) / 100) / 100
|
||||||
{- | Set a depth according to a list of numbers.
|
{- | Set a depth according to a list of numbers.
|
||||||
Lists are lexicographically ordered if input values are always less than 100.
|
Lists are lexicographically ordered if input values are always less than 100.
|
||||||
Higher numbers will get placed on top of lower numbers. -}
|
Higher numbers will get placed on top of lower numbers. -}
|
||||||
|
|||||||
+2
-1
@@ -56,7 +56,8 @@ doDrawing pdata w = do
|
|||||||
pic = worldPictures w
|
pic = worldPictures w
|
||||||
wallPoints = map fst wallPointsCol
|
wallPoints = map fst wallPointsCol
|
||||||
-- set the coordinate uniforms ready for drawing elements using world coordinates
|
-- set the coordinate uniforms ready for drawing elements using world coordinates
|
||||||
setIsoMatrixUniforms pdata rot camzoom trans wins
|
--setIsoMatrixUniforms pdata rot camzoom trans wins
|
||||||
|
setPerpMatrixUniforms pdata rot camzoom trans wins viewFroms
|
||||||
depthFunc $= Just Less
|
depthFunc $= Just Less
|
||||||
pmat <- (newMatrix RowMajor $ perspectiveMatrix rot camzoom trans wins viewFroms)
|
pmat <- (newMatrix RowMajor $ perspectiveMatrix rot camzoom trans wins viewFroms)
|
||||||
:: IO (GLmatrix GLfloat)
|
:: IO (GLmatrix GLfloat)
|
||||||
|
|||||||
@@ -50,6 +50,7 @@ loadSounds = do
|
|||||||
foamSprayFadeOut <- Mix.load "./data/sound/foamSprayFadeOut.wav"
|
foamSprayFadeOut <- Mix.load "./data/sound/foamSprayFadeOut.wav"
|
||||||
sineRaisePitchOneSec <- Mix.load "./data/sound/sineRaisePitchOneSec.wav"
|
sineRaisePitchOneSec <- Mix.load "./data/sound/sineRaisePitchOneSec.wav"
|
||||||
sineRaisePitchTwoSec <- Mix.load "./data/sound/sineRaisePitchTwoSec.wav"
|
sineRaisePitchTwoSec <- Mix.load "./data/sound/sineRaisePitchTwoSec.wav"
|
||||||
|
skwareFadeTwoSec <- Mix.load "./data/sound/skwareFadeTwoSec.wav"
|
||||||
return $ IM.fromList $ zip [0..]
|
return $ IM.fromList $ zip [0..]
|
||||||
[ pFireSound
|
[ pFireSound
|
||||||
, click
|
, click
|
||||||
@@ -96,6 +97,7 @@ loadSounds = do
|
|||||||
, foamSprayFadeOut
|
, foamSprayFadeOut
|
||||||
, sineRaisePitchOneSec
|
, sineRaisePitchOneSec
|
||||||
, sineRaisePitchTwoSec
|
, sineRaisePitchTwoSec
|
||||||
|
, skwareFadeTwoSec
|
||||||
]
|
]
|
||||||
|
|
||||||
loadMusic :: IO (IM.IntMap Mix.Music)
|
loadMusic :: IO (IM.IntMap Mix.Music)
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ sineRaisePitchOneSecSound :: Int
|
|||||||
sineRaisePitchOneSecSound = 43
|
sineRaisePitchOneSecSound = 43
|
||||||
sineRaisePitchTwoSecSound :: Int
|
sineRaisePitchTwoSecSound :: Int
|
||||||
sineRaisePitchTwoSecSound = 44
|
sineRaisePitchTwoSecSound = 44
|
||||||
|
skwareFadeTwoSecSound :: Int
|
||||||
|
skwareFadeTwoSecSound = 45
|
||||||
|
|
||||||
drawWeaponSound = 4
|
drawWeaponSound = 4
|
||||||
holsterWeaponSound = 5
|
holsterWeaponSound = 5
|
||||||
|
|||||||
+1
-1
@@ -20,7 +20,7 @@ perspectiveMatrix rot zoom (tranx,trany) (winx,winy) (viewFromx,viewFromy) =
|
|||||||
let scalMat = Linear.Matrix.transpose $ V4
|
let scalMat = Linear.Matrix.transpose $ V4
|
||||||
(V4 (2*zoom/winx) 0 0 (0::GLfloat))
|
(V4 (2*zoom/winx) 0 0 (0::GLfloat))
|
||||||
(V4 0 (2*zoom/winy) 0 0)
|
(V4 0 (2*zoom/winy) 0 0)
|
||||||
(V4 0 0 0.5 0) --scaled to make walls shorter
|
(V4 0 0 1 0)
|
||||||
(V4 0 0 0 1)
|
(V4 0 0 0 1)
|
||||||
rotMat = Linear.Matrix.transpose $
|
rotMat = Linear.Matrix.transpose $
|
||||||
V4 (V4 (cos rot) (sin (-rot)) 0 0)
|
V4 (V4 (cos rot) (sin (-rot)) 0 0)
|
||||||
|
|||||||
+1
-1
@@ -16,7 +16,7 @@ import Geometry.Data
|
|||||||
data RenderType
|
data RenderType
|
||||||
= RenderPoly [(Point3,Point4)]
|
= RenderPoly [(Point3,Point4)]
|
||||||
| RenderBezQ [(Point3,Point4,Point4)]
|
| RenderBezQ [(Point3,Point4,Point4)]
|
||||||
| RenderText [(Point3,Point4,Point3)]
|
| RenderText [(Point3,Point4,Point2)]
|
||||||
| RenderArc (Point3,Point4,Point4)
|
| RenderArc (Point3,Point4,Point4)
|
||||||
| RenderLine [(Point3,Point4)]
|
| RenderLine [(Point3,Point4)]
|
||||||
| RenderEllipse [(Point3,Point4)]
|
| RenderEllipse [(Point3,Point4)]
|
||||||
|
|||||||
+8
-31
@@ -206,37 +206,20 @@ renderBackground pdata rot camZoom (tranx,trany) (winx,winy) = do
|
|||||||
textureBinding Texture2D $= _textureObject <$> _shaderTexture (_backgroundShader pdata)
|
textureBinding Texture2D $= _textureObject <$> _shaderTexture (_backgroundShader pdata)
|
||||||
drawArrays Points 0 1
|
drawArrays Points 0 1
|
||||||
|
|
||||||
setCommonUniforms
|
setPerpMatrixUniforms
|
||||||
:: RenderData
|
:: RenderData
|
||||||
-> Float -- ^ Rotation
|
-> Float -- ^ Rotation
|
||||||
-> Float -- ^ Zoom
|
-> Float -- ^ Zoom
|
||||||
-> (Float,Float) -- ^ Translation
|
-> (Float,Float) -- ^ Translation
|
||||||
-> (Float,Float) -- ^ Window size
|
-> (Float,Float) -- ^ Window size
|
||||||
|
-> (Float,Float) -- ^ ViewFrom
|
||||||
-> IO ()
|
-> IO ()
|
||||||
setCommonUniforms pdata rot camZoom (tranx,trany) (winx,winy) = do
|
setPerpMatrixUniforms pdata rot czoom trans wins vfs = mapM_ (setPerpMatUniform rot czoom trans wins vfs)
|
||||||
setShaderUniforms rot camZoom (tranx,trany) (winx,winy)
|
$ ( (_lightingFloorShader pdata)
|
||||||
( extractProgAndUnis (_lightingFloorShader pdata)
|
: (_backgroundShader pdata)
|
||||||
: extractProgAndUnis (_lightingOccludeShader pdata)
|
: (_textureShader pdata)
|
||||||
: extractProgAndUnis (_lightingWallShader pdata)
|
: (_textureArrayShader pdata)
|
||||||
: extractProgAndUnis (_backgroundShader pdata)
|
: (_pictureShaders pdata)
|
||||||
: extractProgAndUnis (_textureShader pdata)
|
|
||||||
: map extractProgAndUnis (_pictureShaders pdata)
|
|
||||||
)
|
|
||||||
|
|
||||||
setIsoMatrixUniforms
|
|
||||||
:: RenderData
|
|
||||||
-> Float -- ^ Rotation
|
|
||||||
-> Float -- ^ Zoom
|
|
||||||
-> (Float,Float) -- ^ Translation
|
|
||||||
-> (Float,Float) -- ^ Window size
|
|
||||||
-> IO ()
|
|
||||||
setIsoMatrixUniforms pdata rot camZoom (tranx,trany) (winx,winy) = do
|
|
||||||
setShaderUniforms rot camZoom (tranx,trany) (winx,winy)
|
|
||||||
( extractProgAndUnis (_lightingFloorShader pdata)
|
|
||||||
: extractProgAndUnis (_backgroundShader pdata)
|
|
||||||
: extractProgAndUnis (_textureShader pdata)
|
|
||||||
: extractProgAndUnis (_textureArrayShader pdata)
|
|
||||||
: map extractProgAndUnis (_pictureShaders pdata)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
renderShader
|
renderShader
|
||||||
@@ -252,12 +235,6 @@ renderShader shad dat = do
|
|||||||
eticks <- SDL.ticks
|
eticks <- SDL.ticks
|
||||||
return $ eticks - sticks
|
return $ eticks - sticks
|
||||||
|
|
||||||
--renderPictureLayer
|
|
||||||
-- :: PictureShaderData
|
|
||||||
-- -> Picture
|
|
||||||
-- -> IO Word32
|
|
||||||
--renderPictureLayer
|
|
||||||
|
|
||||||
renderFoldable
|
renderFoldable
|
||||||
:: Foldable f
|
:: Foldable f
|
||||||
=> RenderData
|
=> RenderData
|
||||||
|
|||||||
+19
-9
@@ -70,9 +70,9 @@ white, black :: Color
|
|||||||
white = (1,1,1,1)
|
white = (1,1,1,1)
|
||||||
black = (0,0,0,1)
|
black = (0,0,0,1)
|
||||||
|
|
||||||
scaleT :: (Float,Float) -> (Point3,Point4,Point3) -> (Point3,Point4,Point3)
|
scaleT :: (Float,Float) -> (Point3,Point4,Point2) -> (Point3,Point4,Point2)
|
||||||
{-# INLINE scaleT #-}
|
{-# INLINE scaleT #-}
|
||||||
scaleT (x,y) (a,b,(o,s,t)) = (a,b,(o,s*x,t*y))
|
scaleT (x,y) (a,b,(o,s)) = (a,b,(o,s))
|
||||||
|
|
||||||
overPos :: (Point3 -> Point3) -> RenderType -> RenderType
|
overPos :: (Point3 -> Point3) -> RenderType -> RenderType
|
||||||
{-# INLINE overPos #-}
|
{-# INLINE overPos #-}
|
||||||
@@ -104,19 +104,29 @@ overSca :: (Point2 -> Point2) -> RenderType -> RenderType
|
|||||||
overSca f (RenderText vs) = RenderText $ map (scaleT (f (1,1))) vs
|
overSca f (RenderText vs) = RenderText $ map (scaleT (f (1,1))) vs
|
||||||
overSca _ p = p
|
overSca _ p = p
|
||||||
|
|
||||||
stringToList :: String -> [(Point3,Point4,Point3)]
|
stringToList :: String -> [(Point3,Point4,Point2)]
|
||||||
{-# INLINE stringToList #-}
|
{-# INLINE stringToList #-}
|
||||||
stringToList s = zipWith (\x (a,b,c) -> (translate3 x 0 a,b,c))
|
stringToList s = concat $ zipWith (\x -> map (f x))
|
||||||
[0,0.9*dimText..]
|
[0,0.9*dimText..]
|
||||||
$ map charToTuple s
|
$ map charToTuple s
|
||||||
|
where
|
||||||
|
f y (a,b,c) = (translate3 y 0 a,b,c)
|
||||||
--where dimText = 100
|
--where dimText = 100
|
||||||
dimText :: Float
|
dimText :: Float
|
||||||
dimText = 100
|
dimText = 100
|
||||||
|
|
||||||
charToTuple :: Char -> (Point3,Point4,Point3)
|
charToTuple :: Char -> [(Point3,Point4,Point2)]
|
||||||
{-# INLINE charToTuple #-}
|
{-# INLINE charToTuple #-}
|
||||||
charToTuple c = ((0,0,0),white,(offset,dimText,2*dimText))
|
charToTuple c =
|
||||||
where offset = fromIntegral (fromEnum c) - 32
|
[((-50,-100,0), white,(offset,1))
|
||||||
|
,((-50,100,0), white,(offset,0))
|
||||||
|
,(( 50,100,0), white,(offset+1,0))
|
||||||
|
,((-50,-100,0), white,(offset,1))
|
||||||
|
,(( 50,-100,0), white,(offset+1,1))
|
||||||
|
,(( 50,100,0), white,(offset+1,0))
|
||||||
|
]
|
||||||
|
where
|
||||||
|
offset = fromIntegral (fromEnum c) - 32
|
||||||
|
|
||||||
{- Translate a 3D vector in the x and y directions. -}
|
{- Translate a 3D vector in the x and y directions. -}
|
||||||
translate3 :: Float -> Float -> Point3 -> Point3
|
translate3 :: Float -> Float -> Point3 -> Point3
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ preloadRender = do
|
|||||||
aslist <- makeShader "twoD/arc" [vert,geom,frag] [3,4,4] Points pokeArcStrat
|
aslist <- makeShader "twoD/arc" [vert,geom,frag] [3,4,4] Points pokeArcStrat
|
||||||
eslist <- makeShader "twoD/ellipse" [vert,geom,frag] [3,4] Triangles pokeEllStrat
|
eslist <- makeShader "twoD/ellipse" [vert,geom,frag] [3,4] Triangles pokeEllStrat
|
||||||
bezierQuadShader <- makeShader "twoD/bezierQuad" [vert,frag] [3,4,4] TriangleStrip pokeBezQStrat
|
bezierQuadShader <- makeShader "twoD/bezierQuad" [vert,frag] [3,4,4] TriangleStrip pokeBezQStrat
|
||||||
cslist <- makeShader "twoD/character" [vert,geom,frag] [3,4,3] Points pokeCharStrat
|
cslist <- makeShader "twoD/character" [vert,frag] [3,4,2] Triangles pokeCharStrat
|
||||||
>>= addTexture "data/texture/charMap.png"
|
>>= addTexture "data/texture/charMap.png"
|
||||||
-- texture shaders, no textures attached
|
-- texture shaders, no textures attached
|
||||||
fsShad <- makeShader "texture/simple" [vert,frag] [2,2] TriangleStrip $ const cornerList
|
fsShad <- makeShader "texture/simple" [vert,frag] [2,2] TriangleStrip $ const cornerList
|
||||||
@@ -174,7 +174,7 @@ pokeLightingFloorStrat :: RenderType -> [[Float]]
|
|||||||
pokeLightingFloorStrat Render1111{_unRender1111=x} = [flat4 x]
|
pokeLightingFloorStrat Render1111{_unRender1111=x} = [flat4 x]
|
||||||
pokeLightingFloorStrat _ = undefined
|
pokeLightingFloorStrat _ = undefined
|
||||||
|
|
||||||
pokeCharStrat (RenderText vs) = fmap (\(a,b,c) -> concat [flat3 a, flat4 b, flat3 c]) vs
|
pokeCharStrat (RenderText vs) = fmap (\(a,b,c) -> concat [flat3 a, flat4 b, flat2 c]) vs
|
||||||
pokeCharStrat _ = []
|
pokeCharStrat _ = []
|
||||||
|
|
||||||
pokeArcStrat (RenderArc (a,b,c)) = [concat [flat3 a, flat4 b, flat4 c]]
|
pokeArcStrat (RenderArc (a,b,c)) = [concat [flat3 a, flat4 b, flat4 c]]
|
||||||
|
|||||||
Reference in New Issue
Block a user