textured quad vs 2d

Blitz3D Forums/Blitz3D Programming/textured quad vs 2d

hub(Posted 2003) [#1]
Hi !

I'm experimenting textured quads for my game menu. The text was composed using a bitmap font function.

My first results :
First line : quad textured with the text.
Second line : directly display the text in 2d.



Is it possible to have exactly the same quality with the quad method (without blur and deformation) ?

Thanks !


jhocking(Posted 2003) [#2]
There's no way to have exactly the same quality but there are a variety of ways to improve the quality of the text on a textured quad. In particular you need to position the quad exactly right relative to the camera so that each texel (pixel on the texture) is a pixel on the screen. Notice that the text of your textured quad is smaller on screen than the 2D text, indicating that your quad is not positioned exactly correctly and resulting in some blurring.

You might want to look into HUD systems like FONText or Sprite Control (the latter is free) to automate correct positioning.


DrakeX(Posted 2003) [#3]
another thing that gets in the way is that there is no way to turn off texture filtering in BB. texture filtering is what blends the pixels together so that way the texture does not look blocky close up. certain other languages allow you to turn this off on a per-object basis allowing you to have nice crisp textures on HUDs and whatnot.


TartanTangerine (was Indiepath)(Posted 2003) [#4]
To Turn off texture filtering :-

ClearTextureFilters

To turn them back on again :-

TextureFilter "",1+8


DrakeX(Posted 2003) [#5]
NO NO NO no one seems to understand this! i am not talking about mipmapping!

mipmapping is a process in which lower resolution versions of the same texture are created. these lower res textures are then displayed as the object gets progressivley further and further away.

TEXTURE FILTERING is something completely different and has nothing to do with mipmapping. i explained it pretty completely in my last post -- it blends the colors of the pixels together in gradients so the texture does not look blocky CLOSE UP. however this is a problem when you WANT it to look blocky -- like when you're trying to make 2d in 3d. B3D does not currently have a way to shut texture filtering off at all. i would like to see this implemented.


Gabriel(Posted 2003) [#6]
Yeah Drake, I know what you mean. In the sense of Bilinear Filtering ( I don't think Blitz does Trilinear. ) I would also like to see a way of turning it off as it makes it virtually impossible to do any clever UV mapping to put 16 textures into one large texture and thus combine all surfaces into one. You have to play around leaving gaps between textures and putting up with less than perfect tiling of textures. Not good.


EOF(Posted 2003) [#7]
You might want to look into HUD systems like FONText or Sprite Control (the latter is free) to automate correct positioning.
Thanks for the mention Jhocking.

@Hub,
Here is a direct comparison of 2D text and 3D text from my SpriteControl Functions.
There is still a slight blur around the edges of the 3d text. I have used ClearTextureFilters. The example included is called ModifyText3D.bb if you want to have a look.



And a closeup shot:



Rob(Posted 2003) [#8]
DrakeX, even if you turn off ALL filtering it'll STILL LOOK FUNNY.

This is because of sub pixel accuracy: 3D hardware samples the texels, 2D hardware copies.

Therefore even with ZERO filtering and ZERO mipmapping, you will always have a dodgy result. The quality depends on the 3D hardware's sample accuracy, which is generally better in the latest cards.


hub(Posted 2003) [#9]
Thanks a lot !

uhm... in fact, to obtain this, i've already used your code Syntax !!! After understand how your code works, I've just coded my own function to use bitmapfonts. Today, i use a sprite instead a quad.


Function GUI_quad_text (y, Message$)

	Img = CreateImage (GUI_StringWidth(Message$), GUI_StringHeight())

	SeedRnd MilliSecs() 
	tmpfile$=SystemProperty("tempdir")+"scTMP"+Rand(99) + ".bmp"

	SetBuffer ImageBuffer(Img)
	Color 0,0,0
	Rect 0,0,GUI_StringWidth(Message$), GUI_StringHeight(), True
	GUI_Text (0,0,Message$)
	SetBuffer BackBuffer()
	SaveImage Img,tmpfile$
	FreeImage Img

	Sprite = LoadSprite (tmpfile$,4)
	SpriteViewMode Sprite,4

	div# = (GraphicsWidth()/2)

	w# = GUI_StringWidth(Message$) / div# / 2
	h# = GUI_StringHeight()/ div# / 2

	ScaleSprite Sprite, w#, h#

	y2d# = (GraphicsHeight() / 2) - y
	PositionEntity Sprite, 0, y2d# / div#, +1.0001

	Return sprite
	
End Function


Note : Gui_StringWidth(Message$) return the message lenght in pixels with the bitmapfont. Gui_StringHeight() the height of the current used bitmap font. Gui_Text() display the text (classic 2d) using the current bitmap font.

i've a problem to determin exactly how to scale the sprite to correspond exactly to the image file size ! Camera is set to 0,0,0. So i don't understand why the sprite size is different when it displayed ! If somebody can correct my error !?!

Now, i know that i can't apply effects (alpha, scale, color) if i use only my 2d gui_text() function. But for the moment, with an 3d animated clouds background, it's better than the sprite method.

Despite this, with a black background, sprite method work fine (i've always my scale problem!) Perhaps i should use a bitmap font without the black border to have better results with an animated background !!!

I need more time to test this !


DrakeX(Posted 2003) [#10]
Rob - then please explain to me this.



this is made in DB. the one on the left is simply the image being pasted to the screen. the one on the right is 3d plane textured with the texture and with filtering set to off. can you see any difference? i sure can't.

not to mention i've not met one person with any kind of video card that has trouble just switching off filtering to make crisp 2d-like textures. it even works fine for a guy i know with an old low-end SiS inbuilt video card. if it'll run on that piece of crap (i lived with the same card for 2 years) then it doesn't really seem to be video-card specific (unless you run it on an EGA display or something..).

here's the source code, if you feel so inclined to download the DB1 (not DBP... it's crappy) demo and run it.

sync on : sync rate 60
disable escapekey
autocam off

make object plain 1,64,64
set object 1,1,0,1,0,0,0,0

load image "c:\blitz3d\blah1.bmp",1
texture object 1,1

Position object 1,0,0,screen Width()*0.625

repeat

paste image 1,200,208

sync
until keystate(1)
end


if you do, try changing the line

set object 1,1,0,1,0,0,0,0

to

set object 1,1,1,1,1,0,0,0

and you'll notice the fuzziness introduced by texture filtering.

it IS possible; blitz just doesn't have the means!


skidracer(Posted 2003) [#11]
This code shows what I beleive 1:1 texel to pixel rendering in Blitz3D, tested with a 64x64 sprite. Note the EntityPosition offset of -.5,-.5 as documented in dx7 sdk.

; overlay.bb

displaywidth=800
displayheight=600

Graphics3D displaywidth,displayheight
ClearTextureFilters 

cam=CreateCamera()
CameraClsColor cam,100,120,200
CameraRange cam,.1,1000

overlay=CreatePivot()

aspect#=Float(displayheight)/displaywidth
PositionEntity overlay,-1,aspect,1
scale#=2.0/displaywidth

ScaleEntity overlay,scale,-scale,-scale

sp=LoadSprite("simon.bmp")


EntityParent sp,overlay
ScaleSprite sp,4.0/64,4.0/64
SpriteViewMode sp,2

While Not KeyHit(1)
	PositionEntity sp,MouseX()-.5,MouseY()-.5,0
	RenderWorld
	UpdateWorld
	Flip
Wend

End



DrakeX(Posted 2003) [#12]
still doesn't get rid of the fuzziness made by texture filtering.

and for those who think it doesn't matter -- the texture filtering gets in the way of fine details and small text. an interface i made that used fairly small icon buttons was nearly impossible to see what the buttons were because they were so fuzzy.


skidracer(Posted 2003) [#13]
Did you even test it??? The source sprite must be 64x64 pixels and you will get 1:1 ratio sampling - no oversampling / filtering whatsoever.


skidracer(Posted 2003) [#14]
Oops, my bad. Bug only showed up tooling on matrox machine at home rather than Intel gfx at work.

This example does show that once you get your texels positioned correctly you don't get any blurring in Blitz3D, no ClearTextureFilters call required!

See my pixies topic: http://www.blitzbasic.com/bbs/posts.php?topic=24497


DrakeX(Posted 2003) [#15]
very nice! you're the second person i've seen scaling pivots -- very odd indeed.

it works nicely.

and i've lost yet another argument.


*sigh...........................*