How to draw good quality text?

BlitzMax Forums/BlitzMax Programming/How to draw good quality text?

Tibit(Posted 2005) [#1]
Do I need to use a homemade bitmap font?

Or is it possible to make Drawtext draw a not super pixeled font? Right now (When I scale it) it looks awful, not even fit for a debugger.

I want this to work primary in a fullscreen app, but also for window mode.

I have tried LoadImageFont with various flags, but it doesn't seem to work at all, and there is no example so I have no idea if I'm using it correct.. (I want better docs ).

Trying to load a TrueType Font:
Font_Head1 = LoadImageFont( "Graphics\CENTURY.TTF", 42)', BOLDFONT + SMOOTHFONT )
SetImageFont( Font_Head1 )
SetBlend AlphaBlend
Scale 0.5,0.5
DrawText.....


I had this other idea to simply load the font in different sizes instead of scaling it, seems to be the second easiest solution. Though Fonts just don't want to load on my computer, no error, just nothing happens.

And a legal question, which fonts can I use freely? Those that comes with windows? Any good free font site? Any recomendations? And what about code font, where each letter has the same width?


tonyg(Posted 2005) [#2]
You're using drawtext so you need a graphics command.
Scale is setscale
Font_Head1 is type TImagefont.
Graphics 800,600
Font_Head1:TImagefont = LoadImageFont( "verdana.ttf", 42, SMOOTHFONT)
SetImageFont( Font_Head1 )
SetBlend AlphaBlend
SetScale 0.5,0.5
DrawText "HELLO WORLD",0,0
Flip
WaitKey()

BOLDFONT doesn't seem to do much though.


Tibit(Posted 2005) [#3]
First, does your example work for you? When I run it, it does not care about size=42 or size = 23212321, same with Smoothfont and Boldfont. And when I Setscale 0.5, 0.5 I can't read the text, no way it is AA. But however, as before, if I setscale 1,1 then it is super clear, but then I can't make it larger or smaller. And I do need texts of different sizes.

Second, Yes I did set a graphicsmode and Font_Head1 was of the right type, my "example" was taken out of context.


WendellM(Posted 2005) [#4]
What's the internal name of the font you're trying to load (which you see by double-clicking the .TTF file)? For example, if it's "Century Schoolbook" then you'll need to rename the font file to "Century Schoolbook.ttf"

Also, are you sure that the font is being loaded? You could try adding:
If Font_Head1 = Null Then Notify "Font Not Loaded"
after the LoadImageFont line. If Blitz can't load a font, it doesn't give an error, it just uses a fixed-size default font. Here's what I get when the font isn't named properly and the default is used:



And here's what I get when it's named correctly:



However, it looks a little thin due to being shrunk to half size with SetScale (it gets averaged with the surrounding black which makes the strokes thin). Using it at size 21 and not scaling it down looks better:



As for bold, I think that the BOLDFONT flag just tries to fake bold by thickening the strokes; at least I think that's what Blitz3D does - I don't use the flag myself. If you have an actual bold version of the font as a TTF, you can name it properly and load that file (i.e. "Century Schoolbook Bold.ttf" if that's what the internal name is) and it'll look properly bold:



As for fonts that are legal to use freely, the Bitstream Vera family can be redistributed with personal or commercial products, as long as the fonts aren't sold alone. The Arkpandora fonts are good substitutes for Arial, Times, and Verdana that can be redistributed freely, but not sold alone, like Vera (you can extract them from the .tgz file for use in Windows). Both Vera and Arkpandora include some code (monospace) fonts. Ray Larabie's fonts (some are rather bizarre, but others are very good) are also free. All three groups can be redistributed as long as you include the copyright notice/license that they come with, and they can be left in unpacked .TTF form if you like so that the player/user can use them.

It might be acceptable to redistribute other fonts (that you legally own) as long as they're Incbin-ed, Moleboxed, or otherwise unusable directly by the player/user, but it'd be safer to stick with fonts that allow redistribution if you can. If you're really interested, you can see examples of how font companies protect their products here.


LarsG(Posted 2005) [#5]
wow.. thanks for those links, Wendell..
That Larabie dude sure has got some nice fonts... I gotta bookmark this page.. :)


TartanTangerine (was Indiepath)(Posted 2005) [#6]
It's becuase the fonts are mipmapped, the smaller thet get the smoother the GFX card will try to make them look.

Why don't you just use bitmap fonts instead of using the blitz stuff.


Tibit(Posted 2005) [#7]
Wendell, Thanks for the response. I have now tried renaming the Font, but with no luck. I have tried several different, they just won't load. And as you said, that is the problem; loading.

And about the legal, I'm starting to realise that, as Indiepath pointed out, that I don't know why I should not use bitmap fonts.


Diablo(Posted 2005) [#8]
have you got the font directory as where the program is running. Because this used to happen to me because i tho it would load them from the font directory.


Tibit(Posted 2005) [#9]
Unfortunatly, the fonts that I tested I first copied to the same dir as the bmx file.


WendellM(Posted 2005) [#10]
You're welcome, Lars and Wave. :)

That's odd, Wave - I've encountered a few TTF fonts that I couldn't get to load into Blitz (3D & Max), but most work fine. Does any font work with LoadImageFont/DrawText for you?

If you haven't fully decided to go with bitmap fonts, you could email one of the troublesome fonts (that doesn't work for you) to me and I could see if it doesn't work for me as well.


Tibit(Posted 2005) [#11]
There is not a specific font that doesn't work, none does. Can you give me link to some free font that works for you, just so I get it working.

I'm not 100% sure about bitmaps, becuase it will mean a lot of extra work, but it might also be the best solution.


WendellM(Posted 2005) [#12]
Sure - I've put one of Ray Larabie's fonts here.

If you download it and save it as bullpen.ttf, and save the following code in the same folder and run it:
Graphics 800,600
SetBlend ALPHABLEND

Font_Head1:TImagefont = LoadImageFont( "bullpen.ttf", 21, SMOOTHFONT )
If Font_Head1 = Null Then Notify "Font not loaded"

SetImageFont Font_Head1
DrawText "HELLO WORLD", 0, 0

Flip
WaitKey
Then you should see this:



I've also put a compiled version and the font together as a Moleboxed app here if you want to try that.


Tibit(Posted 2005) [#13]
Thanks!

It works now. All my other fonts works too.

I have found the problem, it has something to do with my imports/framework. When I rem framework and all brl.modules I can load the font, it I keep it, the Font = null, but no error that the command LoadImageFont does not exsist.


WendellM(Posted 2005) [#14]
Good - glad you got them all working!

Fonts work here with:

Framework BRL.D3D7Max2D (or Framework BRL.GLMax2D if OpenGL)
Import BRL.FreeTypeFont