It is currently Sat Feb 23, 2019 5:49 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Load ttf Font as a resource not working
PostPosted: Mon Sep 30, 2013 2:06 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Feb 18, 2012 10:21 pm
Posts: 202
Location: Leicestershire
Hi all,
I am trying to load a true type font as a resource in my game with,

Code:
  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.

_________________
P.N.


Last edited by Pot Noodle on Mon Sep 30, 2013 3:21 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Load Game Font
PostPosted: Mon Sep 30, 2013 3:19 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 752
Location: Denmark
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: viewtopic.php?f=27&t=51675

Best regards
Peter

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 7/10, Intel 6800K, Gtx 970, 32 gb ram.


Top
 Profile  
Reply with quote  
 Post subject: Re: Load Game Font
PostPosted: Mon Sep 30, 2013 5:12 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat Feb 18, 2012 10:21 pm
Posts: 202
Location: Leicestershire
Quote:
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.

_________________
P.N.


Top
 Profile  
Reply with quote  
 Post subject: Re: Load ttf Font as a resource not working
PostPosted: Mon Sep 30, 2013 5:46 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sat Feb 19, 2011 10:06 am
Posts: 752
Location: Denmark
@PN

Anytime.
The Texture2Font can create very simple sheets too..

Like this:
image removed

Data text file for the above image:

Code:
;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.

_________________
“Tell me and I forget. Teach me and I remember. Involve me and I learn.”
— Benjamin Franklin
Current configurations: Windows 7/10, Intel 6800K, Gtx 970, 32 gb ram.


Last edited by DK_PETER on Sun Aug 10, 2014 5:22 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: Load ttf Font as a resource not working
PostPosted: Mon Sep 30, 2013 11:06 pm 
Offline
User
User

Joined: Wed Aug 06, 2008 8:21 am
Posts: 72
Works on Windows 7 x86, Windows 8 x64

Code:
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

_________________
PureBASIC v5.41 LTS , Windows v8.1 x64
Forget UNICODE - Keep it BASIC !


Top
 Profile  
Reply with quote  
 Post subject: Re: Load ttf Font as a resource not working
PostPosted: Tue Oct 01, 2013 9:18 am 
Offline
Enthusiast
Enthusiast

Joined: Sat Feb 18, 2012 10:21 pm
Posts: 202
Location: Leicestershire
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. :D

_________________
P.N.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye