News:

Function Finder  Find all the functions within source code files

Main Menu

Font Support

Started by kevin, November 11, 2003, 12:21:29 PM

Previous topic - Next topic

kevin

Here's a small example of the PB's font commands.  In this example the code loads a windows font, then converts it Bitmap font.  You don't have to store your fonts in bitmap format, but it's a lot faster that way.  One  nice feature is that bitmaps fonts can be blended with an image.  This means you can shade, or even cut lines/shapes out of your character set.  All you need is an image to blend with your font.

kevin


kevin

Here's the code...



;===========================================; Make a Font/ Convert it to BITMAP mode.;===========================================

MyBitMapFont=GeTFreeFont()
loadFOnt "Ariel",MyBitMapFont,50,0
MakeBitmapFont MyBitMapFont,$ff

;===================================================================; Make a Font/ Convert it to BITMAP and BLEnd IT with a shaded IMGE;=====================================================================

; First Make the BLEND image

w=100
h=100
createimage 10,w,h
RenderToImage 10
s#=(128.0)/H
c=120
For lp=0 To h-1
 Boxc 0,lp,w,lp+1,Rgb(255-(c/3),255-(c/2),c)
 c=c+s#
Next

MySHadedFont=GeTFreeFont()
loadFOnt "Ariel",MyShadedFont,h-20,0
MakeBitmapFont MyShadedFont,$ffffff
BlendBitmapFont MyShadedFont,10


;===================================================================; Make a Font/ Convert it to BITMAP and BLEnd IT with a shaded/Cheese like IMAGE :);=====================================================================

CopyImage 10,11
RenderToImage 11
For lp =0 to 25
 circlec rnd(w),rnd(h),rnd(5),1,0
next


MyCheeseFont=GeTFreeFont()
loadFOnt "Ariel",MyCheeseFont,h-20,7
MakeBitmapFont MyCheeseFont,$ffffff
BlendBitmapFont MyCheeseFont,11

;==============================================; Tell PB to render to the SCREEN surfaces;==============================================

RenderToScreen 1


Do
 cls 0
 
  SetFont MyBitmapFont
  CenterText 400,20,"Rendering BITMAP ARIEL Font"
 
  DrawImage 10,400-(w/2),100,0
 
   SetFont MyShadedFont
  CenterText 400,230,"Rendering Blended Font"

  DrawImage 11,400-(w/2),350,0

   SetFont MyCheeseFont
  CenterText 400,500,"Cheese Font"
  sync
 loop
 



darryl_bartlett

How on earth did I miss this post in the past?!!!  This is brilliant.  This kind of functionality will save me so much time.  I shudder at the past when I would have to use a paint package to texture a font and then write a route to split the big bitmap into individual bitmaps (one per letter) and then write another routine to paste all the characters to the screen required to make up the text string I wanted to output.

kevin

Thanks man.   Hopefully at some (not too distant) point i'll find time to add an import bitmap to font styled command also.  Ideally so you can load a hand drawn bitmap as a font.  Although you'd have to define the character it uses though, but once that's done, it'd work the same way as any other font.

darryl_bartlett

That would be fantastic.  Something like that would be so useful.  

I don't know if you have seen this program or not, but I have been having a bit of a play with a programs called Bitmap Font Writer which kind of does what you are hinting at.  The URL is http://www.stefan-pettersson.nu/site/bmpfont/

kevin

Thanks man, that looks really good.  Will have a mess around with it later.  

I think we need a little thread for possible related/useful tools like this..

Fash

"I'll find time to add an import bitmap to font styled command"

Wow, how easy will that make things ?
Save having to code a routine to manipulate strings and stuff !!!
Cool :D
For PC game/demo music visit
Future Developments

kevin

yeah it'll be pretty easy.  So all the standard text stuff can display custom fonts..  print/text ..  

I'm glad people like this idea, it was one of my better ones :)

las6

ah, that's a nice feature.
just few things:
why do you use loadFOnt?  B)
what are the values in the end of the LoadFont?
How do we load normal fonts? Plus how are they "rendered"? (could there be antialiasing options for it?)
system specs: Win XP pro, 2700+ (TB), 1024 Mb DDR, Radeon 9600 pro (128).

empty

Quotewhat are the values in the end of the LoadFont?
The syntax is LoadFont FontName$,  Index, Size, Style

QuoteHow do we load normal fonts?
The syntax is LoadFont FontName$,  Index, Size, Style ;)

With LoadFont you load a normal font and you can switch between the loaded fonts with SetFont.
If you want to use a bitmap font (that renders faster and allows the above effects) you use  MakeBitmapFont on a previously loaded normal font.
There will be a command to load pre-defined bitmap fonts, too.

las6

so the size is constant?
and if I want to use different font sizes in the same loop, I need to reload the font again? No wonder the same situation is and fps killer in db. :P
system specs: Win XP pro, 2700+ (TB), 1024 Mb DDR, Radeon 9600 pro (128).

kevin

The size is constant for the font.  While you could re-size true type fonts dynamically, but the support is biased towards bitmap fonts.