News:

Building a 3D Ray Tracer  By stevmjon

Main Menu

Convert Text into an AFX image

Started by kevin, July 01, 2007, 09:57:19 PM

Previous topic - Next topic

kevin

   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  



PlayBASIC Code: [Select]
   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




NOTE: This is obsolette, today we use  PlayFONT to create Compressed Raster Fonts for PlayBASIC V1.64 versions.



Adaz

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

Ádáz

Hungary

Big C.

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?

kevin


    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.