Panels and Huds

Blitz3D Forums/Blitz3D Beginners Area/Panels and Huds

Eric(Posted 2004) [#1]
May I ask What is the best technique for rendering, Game data over a 3D Scene. Sprites, 2d Overlay.

Just need a little advice on what method, is not a resource hog.

Thank,
Eric


Rob Farley(Posted 2004) [#2]
Depends what you're trying to achieve.

Probably your best bet is to create a single surface text routine. However, this is hardly a topic for the begninners area.

2D overlay can have problems with certain 3D cards, so if you're planning on releasing this for cash then you'll probably want to avoid.

Sprites are a nice easy option, this is the option I'd choose for the Beginners area. The downside is that every sprite will use it's own surface so it's not a great technique, however, it's one to use so you can move into the more complex single surface stuff...

Heres one I did a couple of years back...

Basically the font is a single anim image.
The font$ is the list of characters in order in the image.

You then send the new_word function the x,y,words,rgb as a 3 letter hex string (FFF for white F00 for red etc), size of font, if it's centred, and it's alpha value.

As you'll notice the sprites are always at a z of 0, this is because a second camera would be used to render this lot.

Then you've got the final clear_letters function that you use to wipe the letter type out so you can redraw stuff again.

Global fon_text=LoadAnimTexture("gfx\font.png",52,8,8,0,41)

Type letter
	Field mesh
End Type

Function new_word(x#,y#,char$,rgb$="FFF",size#=.2,centre=0,alpha#=1)
	font$="ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:.,- "
	hexy$="0123456789ABCDEF"
	If centre=1 Then x=x-(Float(Len(char))/2)*(size*2)
	If centre=2 Then x=x-Float(Len(char))*(size*2)
	For n=1 To Len(char)
	l.letter= New letter
	l\mesh=CreateSprite()
	ScaleSprite l\mesh,size,size
	PositionEntity l\mesh,x,y,0
	EntityTexture l\mesh,fon_text,Instr(font,Mid(char,n,1))-1
	EntityColor l\mesh,Instr(hexy,Mid(rgb,1,1))*16,Instr(hexy,Mid(rgb,2,1))*16,Instr(hexy,Mid(rgb,3,1))*16
	x=x+(size*2)
	EntityAlpha l\mesh,alpha
	EntityOrder l\mesh,-11
	Next
End Function
	
Function clear_letters()
	For current.letter = Each letter
	FreeEntity current\mesh
	Delete current
	Next
End Function



Rook Zimbabwe(Posted 2004) [#3]
Yeah but you could use it just to post score numbers and that would simplify it would it not??? Routine looks good... very good! :)
-RZ


Eric(Posted 2004) [#4]
It looks like this creates a sprite for each letter am I correct? I Think I need to think more on this.. I want to Draw a hud or similar in photo shop, places for score, and fuel and cargo.. and things like that. I was thinking of making one big Texture of my Hud, Modifying the texture, based on info from the game, drawing to the texturebuffer behind the scenes, and copying it to a sprite that is directly infront of the camera.. Do you think this would work or be too slow.

Am i going in the wrong direction with this?


Mustang(Posted 2004) [#5]
Do you think this would work or be too slow.


Too slow... creating one screen sized HUD would also slow things down because it would be generate twice the fill (because it covers the whole screen), but doing smaller separate bits would not be that much. And modifying & copying screen sized texture every frame is really slow... but try it yourself; make testcode for both cases and check the difference.