Skip to content

Commit

Permalink
Fixed font 9x15 supported.
Browse files Browse the repository at this point in the history
The function text allows to display multiple strings, which are placed among
each other.
  • Loading branch information
mlesniak committed Jun 8, 2011
1 parent c20c2ab commit 104f724
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,19 @@ main = do
vertex $ Vertex3 0.65 (0.65 :: GLfloat) 0.0
vertex $ Vertex3 x y 0.0
-}


color $ Color3 0 1 (1 :: GLdouble)
text (0.65, 0.95) (map show [(1 :: Int)..10])

-- Rectangle
color $ Color3 1 0 (0 :: GLdouble)
renderPrimitive LineLoop $ do
let f (x,y) = vertex $ Vertex3 x (y :: GLfloat) 0.0
mapM_ f [
(0.00, 0.00)
, (1.30, 0.00)
, (1.30, 1.30)
, (0.00, 1.30)]
, (1.30, 1.00)
, (0.00, 1.00)]

-- KEY
, keyHandler = Just $ KeyHandler $ \key state _ ->
Expand Down
15 changes: 15 additions & 0 deletions Window.hs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module Window (
, Image(..)
, loadImage
, drawImage
, text
) where

import Control.Concurrent
Expand Down Expand Up @@ -218,3 +219,17 @@ drawImage (Image obj path) = do
toVertex (x,y) = vertex $ Vertex2 x y


text :: (GLfloat, GLfloat) -> [String] -> IO ()
text (x,y) ss' = do
-- Handle different window sizes correctly by calculating the space between
-- subsequent lines:
Size _ wh <- get windowSize
fs <- (*1.5) `liftM` fontHeight Fixed9By15
render (fs / fromIntegral wh) y ss'
where render _ _ [] = return ()
render h y' (s:ss) = do
print y'
rasterPos $ Vertex3 x y' 0.0
renderString Fixed8By13 s
render h (y'-h) ss

0 comments on commit 104f724

Please sign in to comment.