2

I'm using the Fungen framework for Haskell and there is a function that uses BitmapFonts. The thing is, that the only BitmapFonts I can use are the ones that come with GLUT, here is the data:

data BitmapFont = Fixed8By13 | Fixed9By15 | TimesRoman10 | TimesRoman24 | Helvetica10 | Helvetica12 | Helvetica18

These fonts are very small for my application, and I want to use another BitmapFont, not just these, or make one of these bigger. How can I do it?

Simon Michael
  • 2,278
  • 1
  • 18
  • 21

1 Answers1

1

Here's the source of putGameText:

putGameText :: [Text] -> IO ()
putGameText [] = return ()
putGameText ((text,font,(x,y),r,g,b):ts) = do
    loadIdentity
    color (Color3 r g b)
    rasterPos (Vertex2 x y)
    renderString font text
    putGameText ts

As I understand it, FunGEn's Text type constrains font to a fixed-size BitMapFont:

type Text = (String, BitmapFont, (GLdouble, GLdouble), GLclampf, GLclampf, GLclampf)

but renderString can also take a StrokeFont, which is even more limited in font family but responds to standard OpenGL scaling/transformation/rotation.

So, a good start might be to make myPutGameText that accepts a StrokeFont-capable MyText and does a scaling transform before rendering. Here's some pseudo-code which I hope someone will correct:

type MyText = (String, StrokeFont, (GLdouble, GLdouble), GLclampf, GLclampf, GLclampf)

myPutGameText :: [MyText] -> (GLDouble,GLDouble,GLDouble) -> IO ()
myPutGameText [] _ = return ()
myPutGameText ((text,font,(x,y),r,g,b):ts) (sx,sy,sz) = do
    loadIdentity
    preservingMatrix $ do
      scale sx sy sz
      color (Color3 r g b)
      rasterPos (Vertex2 x y)
      renderString font text
      putGameText ts

For richer font rendering, the answer is probably to integrate something like FTGL.

Simon Michael
  • 2,278
  • 1
  • 18
  • 21
  • I Had replaced the BitmapFont for a StrokeFont changing FunGen's code, but the strokeFonts were too big!. But I didn't know I could change strokeFonts size, I'm going to try it and tell you what happened. Thanks for the answer! – Cristian Suarez Nov 21 '11 at 02:41
  • I changed the strokeFont size but after doing it, the text just appeared at the bottom of the screen, and I couldn't change its position. that just happens after changing its size. I decided to use a fixed bitmapFont in my game, because I don't have time to waste with fonts. Thanks for the answer anyway – Cristian Suarez Nov 29 '11 at 02:35