GUI

Blitz3D Forums/Blitz3D Beginners Area/GUI

Buggy(Posted 2006) [#1]
I asked this awhile ago, but couldn't find the original thread.

How do you guys add a GUI to a 3D game? With 2D commands like DrawImage that could slow down the game? Or with a camera far away from the character catching the GUI and then putting it on the screen, which seems tough?

A third option is to parent the GUI stuff to the character, but then if it is multi-player or the camera backs up, the GUI will be seen, and it will look weird.

Any advice?


TomToad(Posted 2006) [#2]
You could parent the GUI to the camera. In multiplayer games, just hide the GUIs of the cameras not belonging to the current character before rendering.

There is also 3rd party solutions, one that looks pretty good is Sprite Candy.

Also, your second solution, with a camera far away from the character, is not tough at all. As a matter of fact, that is basically how I did my GUI here. The second camera is actually below the plane pointing down, and the GUI is drawn there.

This is how I set up the camera for the hud.
hud = CreateCamera() ;create the camera for the GUI
CameraClsMode hud,False,True ;do not clear screen before rendering but clear z space,
 ;so it will be drawn over items from camera 1 but be able to maintain it's own z-order
CameraRange hud,1,75 ;shorten the range for quicker rendering
CameraProjMode hud,2 ;use orthographic projection
CameraZoom hud,.04 ;This zoom setting seemed to work best for this program.
PositionEntity hud,0,-50,0 ;put camera below plane
RotateEntity hud,90,0,0 ;point camera away from plane.

You just need to make sure that the GUI camera is created after the main camera so that Renderworld renders in the correct order. Beyond that, it's just a matter of putting your GUI elements in front of the camera.


TomToad(Posted 2006) [#3]
Very strange. I pressed the Preview button after I typed the above post, but instead of previewing the post, it ended up being posted and I was taken up one level to Blitz3D Forums/Blitz3D Beginners Area.

Edit:Just tried it with this post. Same thing happened.


Stevie G(Posted 2006) [#4]
I'd go with the single hud camera .. positioned far away from the scene as TomToad suggests and render over the top of the existing camera(s) . Also, look up some pixel perfect algorithms so that it looks like you've drawn it in 2d.

Stevie


AJirenius(Posted 2006) [#5]
I really dont understand as the newbie I am.
you mean the 2Dcommands would slow down the program?

I thought they where pretty fast (especially compared to 3d with some pixel algorithm). What about the sharpness of the graphics?


Buggy(Posted 2006) [#6]
I'm also a relative newbie, but I think that it slows down when using both 3D commands (RenderWorld) and 2D commands (DrawImage) because I guess it has to run both a 3D and 2D engine.

Just a guess...


(tu) sinu(Posted 2006) [#7]
Get sprite candy, saves alot of time and effort and is really simple to use.


Boiled Sweets(Posted 2006) [#8]
get sprite candy!


YellBellzDotCom(Posted 2006) [#9]
Im currently using a mixture of 3d and 3d commands for my little dinky project. Im very happy with the output. My frame rate doesnt really jump around when I hide my 2d GUI. I originally started using meshes with textures but gettting the whole thing to look proper was quite the headbanger, lol. I finally gave up and just went with the 2d commands. I may attack the 3d gui at a later date to see what kind of improvements may be had. And use the 2nd hud camerea advice.


Weetbix(Posted 2006) [#10]
2D slows down because todays graphics cards are based around displaying 3d graphics, everything today is about 3d! so the graphic card developers dont really bother improving the 2d part of graphics cards.


Barnabius(Posted 2006) [#11]
Just get Sprite Candy or nSprite2 and you'll stop worrying about GUI's. Cheap, simple and very effective solution. You also get a source code from which you can learn a lot.

Barney


jfk EO-11110(Posted 2006) [#12]
Sprite Candy may be a good tool, but most of us are here to program, aren't we?

I think the 2D Phobia is kind of exaggerated. As Xyle said, I don't notice a remarkable speed increase when I hide my 2D components.

Other things are much more important, 3D things. And most of all the designer should not lose orientation on what's bearable and what's not. I just played deus ex 2, that was a professional engine at that time. The framerate is horrible most time (sometimes 4 fps), even if my computer fits the requirements. Playing a blitzgame with a constant rate that never drops down to dia-show level was then like a cure for my eyes.

There are pros and cons with 2D vs 3D Gui and Hud stuff.

You can have semitransparent things in 3D, using funky blendmodes and effects. But it's not as easy to get sharp edges. You should use "pixelperfect" 3D sprites, but if you want to use it with multiple resolutions, then it will become complicated. Additionally, for text and values there need to be texture fonts.

2D text has crisp edges, but it easily looks unprofessional when you are not careful with what you're doing.


AJirenius(Posted 2006) [#13]
This is how I did my GUI. (It's not finished but gives you the idea).
I uses both 3D and 2D. 3D is the semitransparent border and the blue framework.
Then I render in the energybars in 2D so I can manage them more easily and cut out just the correct pieces to be visible (as they are shrinking and growing constantly ingame). Names and nationalityflags will be added on as 2D.



Buggy(Posted 2006) [#14]
Looks nice. I take it, however, that there isn't an easy way to get rid of that black shaded area and just have the bars?

Edit: By the way, how did you get that black shaded area instead of solid black? Or is it not a separate camera...


AJirenius(Posted 2006) [#15]
It is on a seperate camera "far far away" but it's alpha blended which effects all graphics in the background (even if its rendered by another camera).
If I just care to make all black "thingies" 0,0,0 instead of just dark they probably would disappear as well.. Havent spent so much time on the HUD though (yet)


Buggy(Posted 2006) [#16]
Thanks for the reply. I got something working - I think it works because of the alpha texture on the HUD object. Thanks for the input.

Game looks really nice, by the way. Do you make your own models?


AJirenius(Posted 2006) [#17]
Thanks, yes Ive made all 2d, 3d, textures, sound and programming by myself. Yes, Im a little proud :) as this is my first project in B3D ever and just a game to learn programming in this great language.


Buggy(Posted 2006) [#18]
All I can say is "crap." Holy crap.


Rook Zimbabwe(Posted 2006) [#19]
silly question but instead of CUTTING the powerbar image... could you not just rescale the image horizontally???


Andy(Posted 2006) [#20]
The reason people are refering you to 3D is that there are problems with 2D causing massive slowdown with some cards some times. Last time this was discussed, the issue was isolated to drivers, but it is inconsistent and neither Nvidia nor ATI cared enough to deal with it.

However, even though this is a real issue outside of BRL's control, we still have people saying 'I don't have any problems here, so you'll be fine', which is, frankly, BS.

There IS a problem, even if some don't experience it, and encouraging newbies to use 2D on 3D without explaining to them that 2D should only be used for a placeholder GUI, and not for release, is wasting their time.

Research pixel perfect alignment or use sprite candy or a similar solution.


Andy