BAIT Community Project (thread 2)

Miscellaneous Forums/Blitz Showcase/BAIT Community Project (thread 2)

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

Well, it's fairly basic and straightforward, so I'll just go ahead and post it here as I'm sure it'll require some editing to be fit into this project, or any other project if anyone else wants the code:

;_functionDrawText
; for Frogger ][: ThreeeDeeep Reeemake
; by 9572AD
; revision 0.01


Function drawText(textstring$, grid_x#, grid_y#, grid_used#=0.0, vert_factor#=1.0, parent=0, red=255, green=255, blue=255, alphaPct=100)
vertX# = (EntityX(gameCam) - 10.0) + 1.25*grid_x
vertY# = (EntityY(gameCam) - 7.05) + 1.3*grid_y

textMesh = CreateMesh()
textSurface = CreateSurface(textMesh)

characters#=Len(textstring$)

For char = 1 To characters#
charval = Asc(textstring$)
textstring$=Right$(textstring$, characters-char)
u0#=((charval-1) Mod 16)
u0#=u0#/16
u1#=(charval Mod 16)
u1#=u1#/16
If u1#=0 Then u1#=1
v0#=(((charval - (charval Mod 16))/16)*0.125)
If charval Mod 16 = 0 Then v0#=v0#-0.125
v1#=((((charval - (charval Mod 16))/16)-1)*0.125)
If charval Mod 16 = 0 Then v1#=v1#-0.125
vert1 = AddVertex(textSurface, (char-1)*1.25, 0, -0.5, u0#, v1#)
vert2 = AddVertex(textSurface, 1.25+(char-1)*1.25, 0, -0.5, u1#, v1#)
vert3 = AddVertex(textSurface, (char-1)*1.25, -1.3, -0.5, u0#, v0#)
vert4 = AddVertex(textSurface, 1.25+(char-1)*1.25, -1.3, -0.5, u1#, v0#)
AddTriangle(textSurface, vert1, vert2, vert3)
AddTriangle(textSurface, vert4, vert3, vert2)
Next

UpdateNormals textMesh
EntityTexture textMesh, textTex
PositionEntity textMesh, vertX#, vertY#, 10
EntityColor textMesh, red, green, blue
alpha#= alphaPct/100.0
EntityAlpha textMesh, alpha#
EntityParent textMesh, parent 

If grid_used# > 0 Then
 textscale# = grid_used#/characters#
 ScaleEntity textMesh, textscale#, vert_factor#, 1
EndIf

Return textMesh
End Function


grid_X is the X coordinate on the grid
grid_Y is the Y coordinate on the grid (this version counts from bottom up, IIRC)
grid_used is how many letters worth of space you want the mesh to actually take up, if you don't want it to take up the same amount of gridspaces as letters
vert_factor scales the text mesh vertically proportional to the gridsize
parent is the entity to parent this entity to, if any
red, green, blue are the RGB values for the EntityColor
alphaPct is the value for the EntityAlpha, stated as an integer from 0-100 for no apparent reason :P

And here's an example of how the font texture must be laid out:


Oh, and it only makes a single line of text. I didn't set up anything to allow multiple lines in the same mesh, so each line of text, or each object label or HUD label, is its own mesh/surface and can be colored or otherwise manipulated independently.