DrawText on Canvas without Antialiasing

BlitzMax Forums/MaxGUI Module/DrawText on Canvas without Antialiasing

Chalky(Posted 2010) [#1]
Apologies if this has been answered before, but having searched the forums I cannot find a solution.

I am using DrawText to write to a canvas. If I use "coure.fon", then the text is drawn beautifully crisp and clear (and black). However, I need to be able to draw both plain and italic text, so am using "cour.ttf" and "couri.ttf" respectively. However, the output is very poorly defined (medium grey) due to BlitzMax antialiasing the font when it draws it to the canvas. Is there a way to switch off this antialiasing or do I need to create an italic version of "coure.fon"?


Ghost Dancer(Posted 2010) [#2]
If you don't use antialiasing it will probably look a bit jagged, but you can turn it off by NOT using the SMOOTHFONT flag on LoadImageFont (it is on by default). You could also try changing the blend mode (see the SetBlend command) when you use DrawText, as you would when using any graphics command.

As an alternative, you can keep the antialiasing but try making the italic font bold (BOLDFONT flag - LoadImageFont) as that might give it the extra definition you need. You can combine the flags as follows:

LoadImageFont("couri.ttf", 12, SMOOTHFONT | BOLDFONT)


Chalky(Posted 2010) [#3]
I am not using the SMOOTHFONT flag on LoadImageFont. However - if it is ON by default how would I turn it off? I have tried LoadImageFont("cour.ttf",13,0) but that makes no difference (interestingly, BOLDFONT, or SMOOTHFONT | BOLDFONT had no effect either). I have also already tried different blend modes but the only one which leaves the font readable (as opposed to solid blocks) is ALPHABLEND.


Ghost Dancer(Posted 2010) [#4]
You are correct for using 0 for no flags. Not sure why it isn't working, I've never had a problem with LoadImageFont.

Is it definately using the font you have specified? i.e. is the path correct? If not Blitz will use its default font which might give misleading results.

Could you post some code so we can see exactly what you are doing.


Chalky(Posted 2010) [#5]
Hi Ghost Dancer,

I am loading fonts like this:
SetAlpha 1.0
SetBlend ALPHABLEND
FontIT=LoadImageFont("couri.ttf",13,0)
FontPL=LoadImageFont("cour.ttf",13,0)

selecting the style like this (from within a custom type):
Method Font_SetStyle(RowID:Int)
	Select ClassData[LineData[RowID].Class].Italic
		Case 0
			SetImageFont FontPL
		Case 1
			SetImageFont FontIT
	End Select
End Method

and writing to the canvas like this:
SetColor 0,0,0
For Local k:Int=0 To RowCount
	If RowTop+k<LineCount
		DrawText Left(LineData[RowTop+k].Body,DrawLength),0,k*FontHeight
	EndIf
Next

I also just tried removing "style=SMOOTHFONT" from Max2d.mod and rebuilding the module, but this made no difference.


Ghost Dancer(Posted 2010) [#6]
Actually, SMOOTHFONT does not antialias, its used for scaling & rotation so my bad there, sorry. However, SetBlend(MASKBLEND) esssentially turns of antialiasing and that definately works.

Not sure why you can't get BOLDFONT working either. I'm currently working on an app that makes extensive use of drawing fonts on the canvas and not had any problems with it.

Are your fonts in the same folder as your app? Otherwise they will not be loaded.


Chalky(Posted 2010) [#7]
They are yes. They are definitely being loaded ok as I have tried different fonts when testing and they all appear correctly on screen. This is what I get:

ALPHABLEND (cour.ttf):
.

MASKBLEND (cour.ttf):
.

ALPHABLEND (coure.fon):
.

The last image is how I want the first one to look like (i.e. non-antialiased). Looks like I'm going to have to create an italic style FON file to do it.


Ghost Dancer(Posted 2010) [#8]
It must be to do with the font definition or how its being rendered. You could try using the standard courier font with the ITALICFONT flag, which will force an italic style - see if that is any better. It might also be the size it is being rendered at - maybe try it a pixel or 2 bigger.


Chalky(Posted 2010) [#9]
I have already tried ITALICFONT on cour.ttf, but it had no effect. I am beginning to wonder if it's a graphics card issue... Thanks for your help though - I'm off to create me an italic version of coure.fon now!