Contextual popup menu in 3D game - Best practices ?

Started by
3 comments, last by StratBoy61 18 years, 1 month ago
Hello all, Today's question is : I want to create a sort of plugin that will enable to display a popup menu in your 3D application. When right-clicking on the ugly beast that just fragged your mate, you will see a popup menu ala windows(TM) just above his horns (assuming the creature is some kind of goat-looking-monster from hell), displaying its 'properties' like name and health just to name a few... You know what I am talking about, right ? Well, so far, I used the billboard technique, and my popup menu is a real-time texture created with the Win32 GDI (I am working with DirectX). It works just fine, but I needed advice regarding the following points : 1) Would directly drawing on the screen be better, rather than using a billboard ? When I say better, it is vague... would it be simpler, faster ? I was actually thinking that there should not really be any advantage of using a billboard, as you want the popup menu to be independent of the depth. If the two-headed monster you right-click on is 2 miles away, I am sure that you would be glad to see his properties to the size of a pixel ;) It could be a concept though, as you could get information only about characters that are not too far from the camera. 2) If the billboard technique is acceptable, do I have other options than using the GDI ? I was thinking of creating a GDI template and filling it by accessing directly the DirectX texture, so that I could quickly create gradient colors and transparency. Is it the way it is usually done ? 3) Could it be interesting to offer this feature as a plugin, with an editor, so that one could create his/her custom popup menu and simply insert it into his 3D game/project ? Or does it already exist ? Thank you in advance for your answers. Cheers StratBoy61
Advertisement
1) Using the billboard technique is far superior since you do not have to lock the back-buffer and copy (slow). Use orthographic projection if you don't want your GUI controls (in this case, popups) to scale with z.

2) I'm not sure exactly what you need, but generaly GDI is not a good idea. You would be better of using textured quads (billboards) for each element of your GUI controls. You get transparancy for free this way (use alpha channel in textures) Again, this is faster since you don't have to lock textures and CPU work is minimized.

3) There exists several nice GUI systems that can do most of the stuff you'll ever need; windows, buttons, listboxes etc. Crazy Eddies GUI is one of them.

Ofcourse creating a GUI lib (and an editor for it) is a nice learning experience and I'm sure there is people out there that would appreciate it if you realeased yours. So go ahead :)
A.w.e.s.o.m.e !

Thank you Dark_Nebula. I am going to take a look at the site that you mentioned.

Now, I do not have any clue about how to draw text on my D3D texture. So far, I shamelessly cheated by creating a Win32 GDI bitmap, on which I drew whatever I needed --including text, and I converted it into a D3D texture. Then, I re-touched it to add transparency and whatever...
Do you know if I can directly use the DirectX fonts to draw on a texture ?
Cheers
StratBoy61
First of all when you said "drawing on the screen" I assumed that you meant "lock the back buffer and copy the pixels directly", pretty much the same idea as when you lock your texture and copy to it. This is indeed a rather costly operation.

A better way is to lock nothing (except maybe vertex buffers, depending on implementation). That is, you build your GUI controls by rendering textured quads directly to your screen. Your popup propably consists of some background and text. What you do is that you split the background in tiles. You have a texture containing all the tiles and to render the background you simply render quads, (using texture coordinates in your tile texture) one for each tile to build up the background.

I'll try some ASCII:

C|T|C
-----
L|M|R
-----
C|B|C

Here you see 9 tiles building up a background.
C = corner (4 different)
T = top
L = Left
R = Right
B = Bottom
M = Content area

Then you render the text over the background. This way you don't have to lock any textures and this tiling technique gives you a lot of flexibility. For example you can scale the control by scaling the T,L,M,R,B tiles (and translating the right corners). The corners would still look correct:

C|TTTTTT|C
---------
L|MMMMMM|R
L|MMMMMM|R
L|MMMMMM|R
----------
C|BBBBBB|C

For the text you can use DX fonts or you can code your own text rendering.
The same idea can be used to create a library of many types of controls.

I know this explination is a bit vague but this site has a nice GUI system tutorial, including text rendering. It's C# and Managed DirectX but you should be able to get the idea.

Also remember that the DX sample framework comes with GUI stuff nowdays.
I think I understood.
So it means that if I want to display GUI, I have to arrange as many square polygons as I have letters and control parts ? Boy, not very exciting and as usual, not very subtle ;)
Well, thank you again for your help. Rate ++

By the way, did you mean that DirectX will provide an API with these features in the future ? So maybe, no use for me to start any tool/utility, right ?
Cheers
StratBoy61

This topic is closed to new replies.

Advertisement