Posted: 17th Jul 2021 14:33
Hello everyone I'm trying to use a truetype font in AGK2 but it seems to still be using the default AppGameKit bitmap font.
+ Code Snippet
SetWindowTitle( "TTC Font test" )
SetWindowSize( 1200, 600, 0 )

SetVirtualResolution( 1200,600 )
SetOrientationAllowed ( 0, 0, 1, 1 )

LoadFont (1,"Arial")
SetTextFont (1,1)


CreateText(1,"This text is at 16 point size")
SetTextSize(1,16)
SetTextAlignment( 1, 1 ) 
SetTextPosition(1,600,44)
SetTextColor(1,250,250,250,255)

CreateText(2,"This Text is at 24 point size")
SetTextSize(2,24)
SetTextAlignment( 2, 1 ) 
SetTextPosition(2,600,88)
SetTextColor(2,250,250,250,255)

CreateText(3,"even at 32 point it does not look like a truetype font")
SetTextSize(3,32)
SetTextAlignment( 3, 1 ) 
SetTextPosition(3,600,132)
SetTextColor(3,250,250,250,255)
`Sync()

rem A Wizard Did It!
do
  Sync()
loop



I compiled and ran with the LoadFont and SetTextFont active then rem'd out and get the same result.. (see attached image)



What am I doing wrong? Help Please.
Posted: 17th Jul 2021 15:33
I found my mistake.. in case it helps.. you need the UseNewDefaultFonts( 1 ) command at initialization and I was a fool and didn't tell it to set the font for each 'text string' this sample code now works..

+ Code Snippet
rem
rem AGK Application
rem

rem Landscape App
//SetDisplayAspect( 4.0/3.0 )

SetWindowTitle( "TTC Font test 2" )
SetWindowSize( 1200, 600, 0 )

SetVirtualResolution( 1200,600 )
SetOrientationAllowed ( 0, 0, 1, 1 )
UseNewDefaultFonts( 1 )


LoadFont (1,"Arial.ttf")
SetTextFont (1,1)


CreateText(1,"This text is at 16 point size")
SetTextSize(1,16)
SetTextAlignment( 1, 1 ) 
SetTextPosition(1,600,44)
SetTextColor(1,250,250,250,255)
SetTextFont (1,1)

CreateText(2,"This Text is at 24 point size")
SetTextSize(2,24)
SetTextAlignment( 2, 1 ) 
SetTextPosition(2,600,88)
SetTextColor(2,250,250,250,255)
SetTextFont (3,1)

CreateText(3,"even at 32 point it does not look like a truetype font")
SetTextSize(3,32)
SetTextAlignment( 3, 1 ) 
SetTextPosition(3,600,132)
SetTextColor(3,250,250,250,255)
SetTextFont (3,1)

rem A Wizard Did It!
do
  Sync()
loop



I did some digging and got my answer, I hope this helps people trying to use truetype fonts in their apps.

Cheers!

Posted: 17th Jul 2021 17:29
great
Posted: 18th Jul 2021 7:59
you need the UseNewDefaultFonts( 1 ) command
i'm not sure about that:


to be clear:


then, i'm surprised your code didn't error on the first SetTextFont (1,1) since there wasn't a text object 1 yet.
Posted: 21st Jul 2021 3:12
UseNewDefaultFonts is unrelated, it's only for the Print command.

Also instead of applying your font to each string, you can SetTextDefaultFontImage to your font choice and now every string will use that font. I think you'll need an image though instead of ttf. Not to be confused with UseNewDefaultFonts.