Page 1 of 1
Load ttf Font as a resource not working
Posted: Mon Sep 30, 2013 2:06 pm
by Pot Noodle
Hi all,
I am trying to load a true type font as a resource in my game with,
Code: Select all
OpenLibrary(0,"gdi32.dll")
CallFunction(0,"AddFontMemResourceEx",?Font,?End_Font-?Font,0,@"1")
CloseLibrary(0)
LoadFont(0,"SFDigitalReadout-HeavyObliq",16)
;=========================================================
DrawingFont(FontID(0))
DrawText(530,320,"TEST")
DrawingFont(#PB_Default)
;=========================================================
DataSection;Fonts
Font: :IncludeBinary "Fonts\SFDigitalReadout-HeavyObliq.ttf"
End_Font:
EndDataSection
This is the basic's of it but it changes the font size but not the font
Any input would be most appreciated.
Re: Load Game Font
Posted: Mon Sep 30, 2013 3:19 pm
by DK_PETER
Hey PN
Normally you use a sheet with predefined characters. That way you're not limited to the fonts available
on a user's system
You can create font sheets with this:
http://www.purebasic.fr/english/viewtop ... 27&t=51675
Best regards
Peter
Re: Load Game Font
Posted: Mon Sep 30, 2013 5:12 pm
by Pot Noodle
That way you're not limited to the fonts available on a user's system
Thats why i want to imbed the font in to the game.
Yes i like your idea but this is fine for a demo or game that requires glossy graphical fonts
but my game just use's a .
ttf font for one number display so i think it's bit overkill for this job
but thanks anyways DK_PETER.
Re: Load ttf Font as a resource not working
Posted: Mon Sep 30, 2013 5:46 pm
by DK_PETER
@PN
Anytime.
The Texture2Font can create very simple sheets too..
Like this:
image removed
Data text file for the above image:
Code: Select all
;Numbers of characters: 10
0123456789
;Image size (x*y): 240 * 57
;Image Offset width:
24
;Image Offset height:
57
All you need to do is to define the characters to use and pluck out the data you need from the data file.
Re: Load ttf Font as a resource not working
Posted: Mon Sep 30, 2013 11:06 pm
by marroh
Works on Windows 7 x86, Windows 8 x64
Code: Select all
EnableExplicit
Procedure CatchFont(*Memory, lMemSize)
Protected lParam1 = 1
ProcedureReturn AddFontMemResourceEx_(*Memory, lMemSize, 0, @lParam1)
EndProcedure
Procedure FreeCatchFont(lMemFont)
ProcedureReturn RemoveFontMemResourceEx_(lMemFont)
EndProcedure
Procedure Main()
Protected lMemFont = CatchFont(?cf1s, ?cf1e - ?cf1s)
Protected lGuiFont = LoadFont(#PB_Any, "DOSEGA", 16) ; <<< Customize
If lMemFont And lGuiFont
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 440, 80,"CatchFont Demo", #PB_Window_SystemMenu)
SetGadgetFont(#PB_Default, FontID(lGuiFont))
TextGadget(0,10,10,400,20,"CatchFont Demo")
Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
CloseWindow(0)
Else
MessageRequester("CatchFont Demo Error", "Couldn't open main window.", #MB_OK | #MB_ICONERROR)
EndIf
Else
MessageRequester("CatchFont Demo Error", "Couldn't load font from memory.", #MB_OK | #MB_ICONERROR)
EndIf
FreeCatchFont(lMemFont)
FreeFont(lGuiFont)
EndProcedure
Main() : End
DataSection
cf1s:
IncludeBinary "DOSEGA.ttf" ; <<< Customize
cf1e:
EndDataSection
Re: Load ttf Font as a resource not working
Posted: Tue Oct 01, 2013 9:18 am
by Pot Noodle
Thanks marroh this works just fine.
Don't know why my code would not work but never mind it's all good now
Thanks again for your help.
