Page 1 of 2

Typeface - Sprite-based font include/module

Posted: Wed Aug 11, 2010 3:56 pm
by STARGÅTE
Pure Basic Module: Typeface - Sprite-based engine for displaying text with bitmap fonts

Direct download of the include: Typeface.pbi (Version 1.4.2)
Download of a zip-file with include, example, two fonts and an editor: Typeface_20180930.zip

Features of the include:
  • Loading of bitmap-fonts (XML or TF)
  • Unicode and Kerning support
  • Displaying and measuring of texts on the screen
  • Changing color and opacity
  • Chaning of size, rotation (also 3D) and bending
  • Alignment and italic
  • ADisplay-clipping and word-wrap
Features of the editor:
  • Loading and saving of bitmap fonts (XML oder TF)
  • Creating of typefaces from TTF-Fonts
  • Editing of the font image
  • Editing of the characters and the kerning pairs
Image

Original post here: https://www.purebasic.fr/german/viewtop ... =8&t=23015

Re: Include - Typeface, Sprite3D-Font (colorable,flexible,mo

Posted: Thu Aug 12, 2010 6:43 am
by idle
That's great, was going to look into doing something like this myself next week.

Re: Include - Typeface, Sprite3D-Font (colorable,flexible,mo

Posted: Fri Aug 13, 2010 7:32 am
by Kwai chang caine
Nice...thanks 8)

Re: Include - Typeface, Sprite3D-Font (colorable,flexible,mo

Posted: Tue Aug 17, 2010 5:28 pm
by Comtois
Great, Thank you.

Re: Include - Typeface, Sprite3D-Font (colorable,flexible,mo

Posted: Mon Jan 24, 2011 5:01 pm
by Rook Zimbabwe
Looks great and I plan to see if it can be implemented with my new idea! 8)

Re: Include - Typeface, Sprite3D-Font (colorable,flexible,mo

Posted: Mon Jan 24, 2011 8:38 pm
by OldSkoolGamer
Sweet !! I was just looking for something like this myself, saves me some time. :D

Re: Include - Typeface, Sprite3D-Font (colorable,flexible,mo

Posted: Mon Jan 24, 2011 10:55 pm
by Rook Zimbabwe
How can I integrate this with OGRE? It does not seem to want to display in PB4.51 :cry:

Re: Include - Typeface, Sprite3D-Font (colorable,flexible,mo

Posted: Tue Jan 25, 2011 12:02 am
by STARGÅTE
@Rook Zimbabwe
I don't think it runs on OGRE,
because I use a DX9 structure to change the color and vertice of the Sprite3D

I change all the things (rotation, zoom, color, position, ...) in this structure.
I do not know how it is in OREG.

for transform you can use TransformSprite3D(), but for clipping and color i need this DX9 structure.

@All
nice that some of you can use the include
If I have time I try to write an editor, with which you can easily create my *.tf format from an images or *.TTF font

Re: Include - Typeface, Sprite3D-Font (colorable,flexible,mo

Posted: Thu Jul 11, 2013 11:05 pm
by STARGÅTE
Here is an update of my Typeface includes for PB 5.20 and some changes:

Typeface.zip (outdated)
Needs PB 5.20 !

Features:
  • display text with any character sets (XML & Image)
  • intensity and color support
  • (clean) zoom, rotate and bend
  • italic support with any angles
  • unicode, kerning and letter spacing
Image

XML structure:

Code: Select all

<Typeface Image="Example.png"> <!-- file name of the image -->
   <Character Index="65"> <!-- character with index -->
      <Source X="344" Y="38" Width="27" Height="38"/> <!-- position and size in the image -->
      <Outlay X="-8" Y="-8" Width="11" Height="22"/> <!-- display offset and text flow size ->
   </Character>
   <KerningPair Left="39" Right="65" Amount="-1"/> <!-- kerning pair with both characters and their shift -->
</Typeface>

Re: Include - Typeface, Sprite-Font

Posted: Fri Jul 12, 2013 7:32 am
by davido
Another incredible piece of work!
Game-changer!
Love it! :D

Oh, and thanks for sharing.

Re: Typeface - Sprite-based font include/module

Posted: Sun Sep 30, 2018 4:39 pm
by STARGÅTE
Dear all,

I have updated my Typeface include:

Pure Basic Module: Typeface - Sprite-based engine for displaying text with bitmap fonts

Direct download of the include: Typeface.pbi (Version 1.4.2)
Download of a zip-file with include, example, two fonts and an editor: Typeface_20180930.zip

Features of the include:
  • Loading of bitmap-fonts (XML or TF)
  • Unicode and Kerning support
  • Displaying and measuring of texts on the screen
  • Changing color and opacity
  • Chaning of size, rotation (also 3D) and bending
  • Alignment and italic
  • ADisplay-clipping and word-wrap
Features of the editor:
  • Loading and saving of bitmap fonts (XML oder TF)
  • Creating of typefaces from TTF-Fonts
  • Editing of the font image
  • Editing of the characters and the kerning pairs
Image

Original post here: https://www.purebasic.fr/german/viewtop ... =8&t=23015

Feedback is welcome :) .

Re: Typeface - Sprite-based font include/module

Posted: Sun Sep 30, 2018 4:53 pm
by RSBasic
Nice

Re: Typeface - Sprite-based font include/module

Posted: Sun Sep 30, 2018 5:48 pm
by Fig
Very nice !
How fast is it compared with DrawText() ?

Re: Typeface - Sprite-based font include/module

Posted: Sun Sep 30, 2018 6:54 pm
by STARGÅTE
Fig wrote:How fast is it compared with DrawText()?
It's much faster!, because you don't need a StartDrawing() and #PB_2DDrawing_Transparent mode which is very slow compared to the Sprite-Lib with DisplayTransparentSprite.

Here my results:

Code: Select all

Characters | Typeface | DrawText
180          3500 FPS   108 FPS
1800          700 FPS    13 FPS
18000          80 FPS    <1 FPS
I can only advise against using DrawText in games!

Test code:

Code: Select all

InitSprite()

Enumeration
	#Window
	#Typeface
	#Sprite
	#Font
EndEnumeration

IncludeFile "Typeface.pbi" : UseModule Typeface

Declare FPS()

OpenWindow(#Window, 0, 0, 700, 520, "Typeface Example", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Window), 0, 0, WindowWidth(#Window), WindowHeight(#Window), 0, 0, 0, #PB_Screen_NoSynchronization)
SpriteQuality(#PB_Sprite_BilinearFiltering)

UsePNGImageDecoder()
UsePNGImageEncoder()

LoadTypeface(#Typeface, "Tahoma20.tf")
LoadFont(#Font, "Tahoma", 16)

Define Characters = 18000

Define Typeface = #False;#True;

Repeat
	
	ClearScreen($000000)
	SpriteBlendingMode(#PB_Sprite_BlendSourceAlpha, #PB_Sprite_BlendInvertSourceAlpha)
	
	ResetTypefaceStyles(#Typeface)
	
	DisplayTypeface(#Typeface, 0, 0, "FPS: "+Str(FPS()))
	
	RandomSeed(0)

	If Typeface
		For I = 1 To Characters/60
			DisplayTypeface(#Typeface, 10, 20+Random(480), "Grumpy wizards make toxic brew For the evil Queen And Jack.")
		Next
	Else
		If StartDrawing(ScreenOutput())
			DrawingMode(#PB_2DDrawing_Transparent)
			DrawingFont(FontID(#Font))
			For I = 1 To Characters/60
				DrawText(10, 20+Random(480), "Grumpy wizards make toxic brew For the evil Queen And Jack.")
			Next
			StopDrawing()
		EndIf
	EndIf
		
	FlipBuffers()
	
Until WindowEvent() = #PB_Event_CloseWindow


Procedure.i FPS()
	
	Static Count.i, Time.i, FPS.i
	Protected CurrentTime
	
	CurrentTime = ElapsedMilliseconds()
	If Time = 0 : Time = CurrentTime : EndIf
	
	If CurrentTime - Time > 1000 
		FPS = 1000 * Count / (CurrentTime - Time)
		Time = CurrentTime
		Count = 0
	EndIf
	
	Count + 1
	
	ProcedureReturn FPS
	
EndProcedure
[/size]

Re: Typeface - Sprite-based font include/module

Posted: Sun Sep 30, 2018 7:11 pm
by RSBasic
Thank you for this performance information.