2D-Gui over a 3D-world

Blitz3D Forums/Blitz3D Beginners Area/2D-Gui over a 3D-world

Abomination(Posted 2011) [#1]
I am drawing my good-old 2D-gui to an image and draw this image to the backbuffer
after rendering all the 3D-stuff.
Now I'm thinking about changing this so, that I Copyrect this image to the texturebuffer of a sprite or a quad.
What advantages and disadvantages are there for this method?
Copyrect to a Texturebuffer is faster than drawing to the backbuffer? But is it always stable on any PC?
There would be no need to refresh the gui to the screen every frame, but it would take twice as much VRAM?
Or is there even a better way to do this?(except changing to a 3D_Gui)
I don't know enough about 3D to know what is preferable.
Any thoughts?


jfk EO-11110(Posted 2011) [#2]
advantages
-you can scale, rotate and alpha-blend your gui easily. 3D FX are easy (eg. Deformation)
-You can antialias the outlines, using alpha
-More blendmodes
-Text may look blurier, not always a pro tho

disadvantages
Slows dows rate
Eats some extra vram
May couse additional troubles and incompatibilities
May complicate the Gui Update

You should know that Upload of something to a texture is always slow. No matter how you do it, as soon as it goes from the CPU to the Vram, there is a huge impact. You can copy from one texture to an other very fast, also from an image to an other image, or from an image to a texture etc. That's all very fast, But as soon as you try to alter a texture, eg. by copyrect from backbuffer to texturebuffer, there's a siginificant hit.

You maybe best use the Textureflag 256 and see how fast it is. This will turn off Mipmapping and you should try to position the Quad "pixelperfect" (archives/search) to prevent the texels from bluring when they get stretched over the edges of a screen pixel. It may or may not be a lil tricky to get it working pixelperfectly in all resolutions. That's also a diffrence between 2D and 3D: In 2D the Gui will be unscaled, eg. a Button will always be 20 Pixels high. But in 3D it will be scaled automaticly, depending on the screen resolution a Button may be for example 16 Pixels high (in 640*480), or 32 Pixels (in 1280*960). You have to do some extra steps if you want the gui to be "unscaled" as with the 2D Gui.

But I think it's really worth all the troubles. Guis can look very nice when they are translucent, or faded in. And there is also the additional blendmode, for shiny fx.


D4NM4N(Posted 2011) [#3]
I wrote this a long time ago to do something similar to what you are wanting.
http://blitzbasic.com/codearcs/codearcs.php?code=1359

You might need to play with the numbers, maybe not, but if i remember it should create a 640x480 "pixel" overlay in any 3d resolution of the same ratio.

bitmap blitting to the backbuffer is not only slow with some major 3d cards, it also has some horrible limitations (like no alpjha!). The only advantage is crispness of graphics (altough there is no reason why you cannot improve on my old crud to produce some crispy results)

If i remember another "downside" to using "3D2D" is all the images should be power of 2. Although there are lots of cheats for this including; incuding 4 things on 1 image and drawing the unwanted bits offscreen, to using large areas of alpha where an image is only 512x256.

Last edited 2011


Abomination(Posted 2011) [#4]
@D4NM4N: Thanks for the input.
But I have moved on since last week. ;)
I use quads on a singlesurface, on a mesh scaled to make the textures appear pixelperfect.
It's pretty fast and (vercitile) [<-bad engrish].
The biggest bottleneck is now updating the content by copyrecting to the texturebuffer.
But there is no need to do that every frame, so I'm quite content.