News:

PlayBASIC2DLL V0.99 Revision I Commercial Edition released! - Convert PlayBASIC programs to super fast Machine Code. 

Main Menu

Bitmap Font Example

Started by kevin, March 25, 2006, 08:17:51 PM

Previous topic - Next topic

kevin

Bitmap  Font example


PlayBASIC Code: [Select]
; ---------------------------------------------------------- 
; For This example, were going to build a PB Bitmap font
; from the Windows Arial font as an example. Normaly you'd
; load a set of predrawn characters and import those...
; ----------------------------------------------------------


; Load the Windows True Type Font Ariel (50 point)
Loadfont "Ariel",2,50,1
setfont 2

; Set the Width + Height of oru custom font
ChrWIdth=48
ChrHeight=60

; create some temp images that weill be used during
; creation
TextureIMage=NewIMage(ChrWidth,ChrHEight)
TextureIMage2=NewIMage(ChrWidth,ChrHEight)


CreateBitmapFont 10,ChrWidth,ChrHeight

; uv cords for texture mapper
u1=0
v1=0
u2=ChrWidth
v2=0
u3=u2
v3=ChrHeight
v4=0
v4=v3

; Vertex

x1=0
y1=0
x2=chrWidth
y2=0
x3=x2
y3=ChrHeight
x4=0
y4=y3


x5=ChrWidth/6
y5=ChrHeight/6

x6=chrWidth-x5
y6=y5

x7=x6
y7=ChrHeight-y5

x8=x5
y8=y7



; Manually Create the characters of our bitmap font
For lp=Asc(" ") to asc("z")
; direct all render to the temp texture image
RendertoIMage TextureIMage

; Draw a random shade box for each chr's backdrop
ShadeBox xpos+0,0,xpos+Chrwidth,Ypos+ChrHeight,rndrgb(),rndrgb(),0,lp

; direct all rendering to the second temp texture
RendertoIMage TextureIMage2
Drawimage Textureimage,0,0,false

; Draw the character and it's shadow
ink rgb(32,32,32)
Centertext xpos+(chrwidth/2)-2,ypos-2,chr$(lp)

ink rgb(64,64,64)
Centertext xpos+(chrwidth/2)-1,ypos-1,chr$(lp)

; Centertext xpos+(chrwidth/2),ypos,chr$(lp)
ink rgb(200,240,255)
Centertext xpos+(chrwidth/2),ypos,chr$(lp)


RenderToScreen

TextureQuad TextureImage,x1,y1,u1,v1,_
x5,y5,u2,v2,_
x8,y8,u3,v3,_
x4,y4,u4,v4,false

TextureQuad TextureImage,x1,y1,u1,v1,_
x2,y2,u2,v2,_
x6,y6,u3,v3,_
x5,y5,u4,v4,false

TextureQuad TextureImage,x6,y6,u1,v1,_
x2,y2,u2,v2,_
x3,y3,u3,v3,_
x7,y7,u4,v4,false


TextureQuad TextureImage,x8,y8,u4,v4,_
x7,y7,u3,v3,_
x3,y3,u2,v2,_
x4,y4,u1,v1,false


TextureQuad TextureImage2,x5,y5,u1,v1,_
x6,y6,u2,v2,_
x7,y7,u3,v3,_
x8,y8,u4,v4,false

; This the section of screen at position 0x,0y for
; This character in font 10
getFontChr 10,lp,0,0
next

ydir=1

Do
; Clear the Screen
Cls 0

; Tell PB to use the newly created bitmap font
Setfont 10

; Calc the screen center
cw=GetScreenWidth()/2
ch=GetScreenHeight()/2

centertext cw,ch-(chrheight/2),"PlayBasic"
restore "start"
Ypos=Y
repeat
t$=readdata$()
if T$<>"start" and T$<>"end"
centertext getscreenwidth()/2,Ypos,t$
ypos=ypos+chrheight
if ypos>GetSCreenheight() then exit
endif
until t$="end"

y=y+ydir

if Y>(getscreenheight()-150) then Ydir=-Ydir
if Y<-(getscreenheight()-150) then Ydir=-Ydir
sync
loop
Login required to view complete source code



thaaks

Oh, that's a nice example!
So we can create our own bitmap fonts the way we like. Now who's going to write a bitmap font editor in PB?  :D

Is it somewhere documented that you can end a line with '_' and it contines in the next line?
Does that also work for my own functions and their parameter lists?

Cheers,
Tommy

kevin

QuoteIs it somewhere documented that you can end a line with '_' and it contines in the next line?

Prolly not :)


QuoteDoes that also work for my own functions and their parameter lists?

It won't work in function declarations, but it should work within any expression.