This function converts a text message into an AFX image. AFX formatted images support Alpha channel (32bit only) so you can get an Anti Aliased look when rendering text to Video or FX formatted surfaces. The AFX format is only support via drawimage though.
Since window text is anti aliased by default, All the function does is created a video image (black) and renders the text message to that in pure white. This creates a gray scale representation of the message. So we can then take any channel we like and use that as the alpha channel (in this case it uses the blue). Probably best to precalc a bunch of these in your games though
[pbcode]
Size=75
MyFont=LoadnewFont("Arial",Size,0)
Setfont MyFont
t$="www.PlayBasic.com"
; Convert that Row into a FX image with Alpha channel support (32bit only!)
i=COnvertTextToAFXimage(t$,Rgb(0,255,0))
Xpos=50
Ypos=300
Do
Cls rgb(100,40,140)
inc Frames
t=timer()
text Xpos,Ypos,t$
tt1#=tt1#+(timer()-t)
t=timer()
drawimage i,Xpos,Ypos+Size,true
tt2#=tt2#+(timer()-t)
;
print "Speed"
print tt1#/frames
print tt2#/frames
Sync
loop
Function ConvertTextToAFXimage(t$,TextColour)
OldSurface=getSurface()
tw=gettextwidth(t$)
th=gettextheight(t$)
ThisImage=NewImage(tw,th)
RenderToIMage ThisImage
ink rgb(255,255,255)
text 0,0,t$
PrepareAFxImage ThisImage
r=rgbr(textCOlour)
g=rgbg(textCOlour)
b=rgbb(textCOlour)
RenderToImage Thisimage
lockbuffer
NullPixel=Point(0,0)
For Ylp=0 to Th
For Xlp=0 to Tw
ThisRGB=FastPoint(Xlp,yLp)
dotc xlp,ylp,argb(RgbB(ThisRGB),R,G,B)
next
next
unlockbuffer
rendertoimage OldSurface
EndFUnction ThisImage
[/pbcode]
NOTE: This is obsolette, today we use PlayFONT (http://www.underwaredesign.com/forums/index.php?topic=3103.0) to create Compressed Raster Fonts for PlayBASIC V1.64 versions.
Please notice the differences between 1.63v and 1.71g screenshots and FPS values.
Why?
remark: the bottom image is not anti aliased at all
Hi Kevin,
in the last Beta Help package I didn't find a "Help on Keyword" site for the command PrepareAFXImage... If you examine the latest history.txt you will found that this command was included with Version 1.48c of PlayBasic... Need for PB LE?
The AFX format is not officially supported and obsolete in 1.7x higher revisions. Why ? - because not all rendering methods have a AFX render mode.