   How to create a HUD
  Hey guys,I'm making a game in c++ using directX graphics and I was wondering is there is a simpler way of creating the HUD than re-drawng it piece by piece every frame. It's just a rather complicated thing to redraw each turn that also happens to be fairly static, so I was wondering if there was a simpler way.So... is there?   
Quote:Original post by ShadekfHey guys,I'm making a game in c++ using directX graphics and I was wondering is there is a simpler way of creating the HUD than re-drawng it piece by piece every frame. It's just a rather complicated thing to redraw each turn that also happens to be fairly static, so I was wondering if there was a simpler way.So... is there?Draw the HUD to a texture and make (partial) updates to that texture whenever a part of the HUD changes, then draw the entire texture on top of your scene every frame.   ;  Is your current method too slow? Do you have performance issues with your code?If not then stick with that you're currently doing. If you do, then you could share your implementation details with us and we can probably help you at optimizing.   ;Quote:Original post by ShadekfIt's just a rather complicated thing to redraw each turn that also happens to be fairly static, so I was wondering if there was a simpler way.What is it that makes this particularly complicated? If redrawing a hud is already complicated, how difficult is it going to be to render the rest of your game? Perhaps you need to spend some time writing code to make rendering things easier. How are you currently rendering things?   ;  In my game engine, I've wrapped the HUD into a Manager class to simplify how I can use it.  Basically it works like this.  At the start I add items into my manager and when I want to update a specific item I have function calls that allow me to do that.  If I don't update anything then the last state is used.  When it comes to render I call manager.render(); and that's it.  If you want to see the implementation details, check out my website.   ;  Thanks guys you given me something to think about.Really I'm just planing what code I'm about to write, and manually drawing each object seperately every frame seemed like a long winded approach seeing as the hud doesn't change constantly (I'm making a Strategy game). I was just wondering if there was easier way of doing it. For example java has frames, the idea being that each frame can almost be seen as a different screen and they are intelligent enough that they know when you click in and out of them. Also then you don't have to consider the camera and moving the hud in relation to your world, you just need to write the hud once into that frame and leave it be until you need to change something. I was sort of hoping there was a c++ equivalent, although it doesn't seem as though there is.   ;Quote:Original post by ShadekfAlso then you don't have to consider the camera and moving the hud in relation to your world,<snip>Actually, you *are* doing it wrong, then. If I read that correctly, you're actually placing the HUD objects in the world?... you do realize the DirectX 9 has the XYZRHW vertex attribute thingy to bypass all that entirely? You just specify the coordinates directly and they'll show up where they're supposed to in the current viewport. Granted, that's an oversimplification, but there's no possible reason why that kind of stuff should be handled in world space.;Quote:Original post by ShadekfReally I'm just planing what code I'm about to write, and manually drawing each object seperately every frame seemed like a long winded approach seeing as the hud doesn't change constantly (I'm making a Strategy game).Again, what's 'manual' about it? You're writing code to do it for you. Besides, that hud has to be drawn to screen every frame anyway - it's not worth it to go for dirty rectangle-like optimizations with current hardware. Not for a few hud sprites.And yeah, use screen coordinates for huds, not world coordinates.@mmakrzem: Manager is a pretty undescriptive name... I mean, we have managers here too. But they manage projects... ;)   ;Quote:Original post by ShadekfI was just wondering if there was easier way of doing it. For example java has frames, the idea being that each frame can almost be seen as a different screen and they are intelligent enough that they know when you click in and out of them. Also then you don't have to consider the camera and moving the hud in relation to your world, you just need to write the hud once into that frame and leave it be until you need to change something. I was sort of hoping there was a c++ equivalent, although it doesn't seem as though there is.Well, Java as a language doesn't provide that as well. It's the libraries that come with the JDK that allow you to build a gui. Instead of swing you could also use SWT or other toolkits.In C++ you have several options:- use an existing gui library like CEGUI- write your own gui system that can be as simple/complicated as you wishI personally chose the second option and created a simple gui system that was partly inspired by the way swing handles things. Now I just create a (sub)window in my application, give it a layout manager, drop some components into it and let it do the rest. For rendering I just use orthogonal projection, i.e. the projection matrix matches the screen resolution and thus I can use "pixels" to define component sizes.