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