Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: KeldorKatarn on December 13, 2008, 05:56:39 am

Title: Full color HUD
Post by: KeldorKatarn on December 13, 2008, 05:56:39 am
Is anyone working on this?

In principle it should be an alternative to the current hud, using colored ANIs or EFFs and their frames to display the gauges.
For shields more frames would be needed for the shield status since the technique that's used with the monochrome ones to have frame per quadrant wouldn't work.

Saga is especially interested in this, since in conjuncture with being able to position each gauge per fighter we'd be a giant step closer to replicating the WC3 HUD layout and appearance.

I tried playing around a bit in the code, trying to draw a colored ani frame to the HUD, but somehow I didn't look through the graphics code. I managed to draw the thing, but it apeared monochrome white, no matter what I did. Some colors where left away and not displayed so the ani had gaps. I suspect the rendering states have to be set differently but since the graphics API is not exactly well documented I don't really see where the problem is.
I know there's a code freeze but if anyone has the time to help me with the rendering part, I think I could get the logic part of the code done by myself and to be included once 3.6.10 is out.

Also for some reason I couldn't get an eff to be displayed at all although from what I can see those are handled exactly like anis, just the loading code is different. But as those are 24/32bit they are probably not configured right in terms of the render states or the render target.

Any insights here would be appreciated. I BASICALLY would already be happy if someone could tell me how to draw a colored bitmap onto the screen from inside the HUD code.
Title: Re: Full color HUD
Post by: Topgun on December 15, 2008, 07:49:22 pm
Why not just send the HUD file along with the game (or mod)?
Title: Re: Full color HUD
Post by: Backslash on December 15, 2008, 09:13:08 pm
Why not just send the HUD file along with the game (or mod)?
:wtf:

Read it again.  The 'hud file' only controls the single color for each gauge.  The HUD currently takes a ANI in grayscale, colors and saturates it a color from the options screen.  He (and I) want to make gauges that show ANI (or EFF) files as they truly are, with 8-bit or even 16 or 24-bit color.
Title: Re: Full color HUD
Post by: portej05 on December 16, 2008, 08:25:10 am
hmm, this is my first foray into this section of the code.... so I'm probably going to be wrong here (forgive me... please!)
In my checkout of the code (5004), the gauges seem to be drawn at line 1906 of hud.cpp using GR_AABITMAP(a,b,c) defined in hud.h:
Code: [Select]
#define GR_AABITMAP(a, b, c) { int jx, jy; if(emp_should_blit_gauge()) { gr_set_bitmap(a); jx = b; jy = c; emp_hud_jitter(&jx, &jy); gr_aabitmap(jx, jy); } }

So it sets the bitmap and then calls gr_aabitmap which is really (at least, in the OpenGL build) gr_opengl_aabitmap.
I'm not sure why gr_opengl_bitmap has been commented out, but it probably breaks something.
I'd try adding code just before the
Code: [Select]
if(image_ids[i].first_frame != -1) on line 1904 of hud.cpp checking for a flag to say 'use full colour gauges' calling gr_opengl_bitmap, but I haven't got the time to try this out at the moment.
Could one of the code wizards (yes, you! :D) advise if I'm totally insane and off the beaten track?
I'm not sure about side effects of these functions (including gl states) or how to go about adding such a flag.
Title: Re: Full color HUD
Post by: Nuke on December 16, 2008, 07:41:00 pm
i always thought we should have the option to use 24/32 bit textures (and effs) for hud elements. it would sure as hell make the hud easyer to work on. the huds limitations to images with fixed pallettes and 16 shade animations for the sake of color customizability has always annoyed me. id rather abolish that or at least make an iption to allow for colored hud graphics. it would look alot better than the current hud. it would be wise to make it global and allow new formats to be used on all icons, for briefing, loadout, and anywhere else that uses 2d icon images.
Title: Re: Full color HUD
Post by: portej05 on December 16, 2008, 09:30:00 pm
I think (but can't confirm atm) that the flashing effects are obtained by changing the alpha value of the bitmap. I'm not sure how this would work with full colour elements.

Can someone enlighten me about #ifdef NEW_HUD - there's no point taking a crack at this if someone else already is
Title: Re: Full color HUD
Post by: Nuke on December 17, 2008, 02:14:44 am
well if the hud uses hardware surfaces like it should, think it would be possible to dynamically change the alpha values, otherwise animate the blinks.

i just think 16 color images are ugly and should be replaced by something more modern.
Title: Re: Full color HUD
Post by: chief1983 on December 17, 2008, 02:49:31 am
Me too let's do SVG images for the HUD :)

Seriously though, a bit of an update could be nice but I'm hoping for the RTT HUD on a cockpit myself.
Title: Re: Full color HUD
Post by: JGZinv on December 17, 2008, 03:18:19 am
FringeSpace needs more of the animated capability for the HUD, although some simple
things are possible with a lot of tweaking now.

If I could say even work with making animated GIFs, it'd be easier than having
to do PCXs.

Being able to set the colors of the art would be nice, taking it from the file itself.
However I think the adjustable color system of the current setup has it's purposes too.
A blend would be best solution if at all reasonably possible.
Title: Re: Full color HUD
Post by: Nuke on December 17, 2008, 06:24:17 am
Me too let's do SVG images for the HUD :)

Seriously though, a bit of an update could be nice but I'm hoping for the RTT HUD on a cockpit myself.

i should probibly work on that some more, though lately ive been more intrested in programming with opengl. id like a system where every hud element is rtted to a texture (in an array of hud elements). then you can not only move these textures around on the hud (possibly on the fly with the mouse) but also apply them to anything else you can stick a texture on. the alternative would be to render the whole hud as one texture, which could optionally be drawn on some polygons in the cockpit model. it would be better for the dynamic hud idea, however theres the added math of determining certain hud elements, like lead indicators, based on view angle, distance from the camera, fov, etc. 

you can recreate the gauges in scripting and render those to the panel, but it seems somewhat redundant if you ask me. then again the hud is supposed to be a simplified version of the panel, so more complex instruments might look better down there. frankly im not sure i understand how scripting works anymore (you never see my scripts run newer hooks for example).
Title: Re: Full color HUD
Post by: portej05 on December 17, 2008, 09:04:48 am
Actually, modifying this is going to be a lot more complex than just one code change - components of the HUD are drawn in lots of separate functions (anyone got any documentation?) :)
Title: Re: Full color HUD
Post by: Swifty on December 17, 2008, 01:01:20 pm
Me too let's do SVG images for the HUD :)

Seriously though, a bit of an update could be nice but I'm hoping for the RTT HUD on a cockpit myself.

i should probibly work on that some more, though lately ive been more intrested in programming with opengl. id like a system where every hud element is rtted to a texture (in an array of hud elements). then you can not only move these textures around on the hud (possibly on the fly with the mouse) but also apply them to anything else you can stick a texture on. the alternative would be to render the whole hud as one texture, which could optionally be drawn on some polygons in the cockpit model. it would be better for the dynamic hud idea, however theres the added math of determining certain hud elements, like lead indicators, based on view angle, distance from the camera, fov, etc. 

you can recreate the gauges in scripting and render those to the panel, but it seems somewhat redundant if you ask me. then again the hud is supposed to be a simplified version of the panel, so more complex instruments might look better down there. frankly im not sure i understand how scripting works anymore (you never see my scripts run newer hooks for example).
I'm actually toying with that. I've been experimenting with rendering HUD elements to a texture using OpenGL render targets and making the HUD texture available for drawing by creating methods in LUA called drawRadar(), drawTargetBox(), etc. That way if you have a display on a cockpit model you want the target box on, you can just call drawTargetBox() on a texture, then replace the display screen texture with the one you just rendered on.
Title: Re: Full color HUD
Post by: WMCoolmon on December 19, 2008, 02:20:52 am
I think (but can't confirm atm) that the flashing effects are obtained by changing the alpha value of the bitmap. I'm not sure how this would work with full colour elements.

Can someone enlighten me about #ifdef NEW_HUD - there's no point taking a crack at this if someone else already is

NEW_HUD was a HUD designed with the idea that every gauge would be implemented as its own separate class that depended on an object pointer that could be any ship whatsoever, which would be fully object-oriented and flexible like the gauges in hud_gauges.tbl. There's some drawing code to do different shapes for the HUD and so on, as well as an integrated variable class that lets you specify strings and integers and so on and autoconverts those to whatever form is needed. It's been years since it was worked on. Might be a good starting point for a new HUD system but I thought somebody else was working on something completely different, and much more ambitious.

hmm, this is my first foray into this section of the code.... so I'm probably going to be wrong here (forgive me... please!)
In my checkout of the code (5004), the gauges seem to be drawn at line 1906 of hud.cpp using GR_AABITMAP(a,b,c) defined in hud.h:
Code: [Select]
#define GR_AABITMAP(a, b, c) { int jx, jy; if(emp_should_blit_gauge()) { gr_set_bitmap(a); jx = b; jy = c; emp_hud_jitter(&jx, &jy); gr_aabitmap(jx, jy); } }

So it sets the bitmap and then calls gr_aabitmap which is really (at least, in the OpenGL build) gr_opengl_aabitmap.
I'm not sure why gr_opengl_bitmap has been commented out, but it probably breaks something.
I'd try adding code just before the
Code: [Select]
if(image_ids[i].first_frame != -1) on line 1904 of hud.cpp checking for a flag to say 'use full colour gauges' calling gr_opengl_bitmap, but I haven't got the time to try this out at the moment.
Could one of the code wizards (yes, you! :D) advise if I'm totally insane and off the beaten track?
I'm not sure about side effects of these functions (including gl states) or how to go about adding such a flag.

AABITMAP is right. gr_aabitmap draws the current bitmap (gr_set_bitmap) in shades of the current color (gr_set_color). There is an analogous function in scripting that you can play with (drawMonochromeImage) that basically just calls aabitmap. A hud_gauges flag or something would be the quick and easy solution.
Title: Re: Full color HUD
Post by: portej05 on December 19, 2008, 03:35:43 am
Does anybody want me to pursue this (i.e. If anybody is already working on this squeak now - a duplication of efforts is a pain in the rear end)
Are there any documents on how the bitmaps section works?
Title: Re: Full color HUD
Post by: Backslash on December 21, 2008, 04:43:13 pm
I've been working off and on, on the coordinates part of this... basically I'm expanding hud_gauges.tbl (http://www.hard-light.net/wiki/index.php/Hud_gauges.tbl) to include every gauge and part.  This has the nice bonus of being able to customize the hud per-ship.  It's taking me longer than planned, Real Life reared up and bit me in the meantime...

Unfortunately I started this a while ago so it was based on the old 'head' 'branch' which we now call unstable.  I'm in the process of porting it to a trunk build.  I'm not sure what you plan to work on, but I'd be glad to share my work with you if you're interested.  I'm not the best coder, so it'd be nice to have someone else help fill in my gaps. :)

Title: Re: Full color HUD
Post by: portej05 on December 21, 2008, 09:09:12 pm
ah cool
The basic plan is to execute in a few steps:
1) Create some documentation for the HUD system (how it works and where it pulls data from)
2) Find some documentation for the drawing system (I've got no idea how it works atm)

This is my first real foray into the codebase, so I'm going to be a little slower than if I knew it.
I think the aim at the moment (hence figuring out how it currently works) is to add some support for full coloured bitmaps, but it is starting to get ugly - you've just pointed out another dependency that I missed!

There appears to be an earlier effort to create a new HUD system - is this a path you want to go down? or would you prefer a cleanup and tack on the full coloured bitmaps?

I'm going to be a bit slow over the next week or two (real life!), but after that I will have some larger chunks of time to look at this

I'll PM you my email address (I'm not sure if you can just email me from the forum software...) - if you could send me what you've done, that would be great!

EDIT: Fix dodgy some grammar
EDIT2: Fixed*
Title: Re: Full color HUD
Post by: portej05 on December 22, 2008, 07:07:37 am
Any insights here would be appreciated. I BASICALLY would already be happy if someone could tell me how to draw a colored bitmap onto the screen from inside the HUD code.
The closest I can figure (I haven't tried this yet - haven't figured out how to get a coloured bitmap into the system yet!) is to do this:
Code: [Select]
gr_set_bitmap(bitmap_id);
gr_bitmap(x, y);
Where bitmap_id is the index of the bitmap you want to use and x and y are the 640x480 or 1024x768 coordinates
There's another function g3_draw_2d_poly_bitmap, but it is wrapped by gr_bitmap, so I'd use that rather than g3_draw_2d_poly_bitmap.
Hope that helps
Title: Re: Full color HUD
Post by: WMCoolmon on December 22, 2008, 05:58:22 pm
Yeah, that's right. Several of the scripting functions implement 2d drawing stuffs so you might want to take a look at those in lua.cpp. They do use more advanced functions for resizing/cropping the image, and also use absolute screen coordinates where possible.
Title: Re: Full color HUD
Post by: portej05 on December 26, 2008, 12:57:19 am
hmm.. there have been a lot of ideas in this thread  :eek:

Does anybody know how they want to proceed with this?

Looking at the SCP Dev Roadmap, the HUD is on the hitlist for 3.7.0.
I do like the SVG idea for HUD elements :D.
Title: Re: Full color HUD
Post by: chief1983 on December 26, 2008, 01:09:46 am
That dev roadmap, really doesn't mean much these days I don't think.  With the hopefully accelerated release process, it'll be more, get a few features in, test them, release.  All that roadmap really represents is the amount of time and complexity estimated for each feature on it.  If it's done in Lua then it really has nothing to do with the roadmap.  And if any code changes aren't as bad as people expected them to be, then it shouldn't be an issue to get them in during the next open commit cycle.
Title: Re: Full color HUD
Post by: portej05 on January 05, 2009, 11:31:51 pm
Does anybody have any advice on how to proceed with this? I'm not quite sure what I'm aiming for anymore (scripting, other people working on stuff and the ideas in this thread are complicating this!)
Title: Re: Full color HUD
Post by: WMCoolmon on January 05, 2009, 11:58:45 pm
Doing a full-color HUD with scripting should be possible right now. What isn't available is all the information needed to create a full HUD. Animations, etc. are also possible, but you have to write the scripting to go through each of the frames in the correct time period, using the texture handle properties (FPS, etc) and ba.getFrametime().

I don't know what other people are doing for the HUD. IMHO the only "proper" solution is to rip the old system out and replace it with something new that's capable of reproducing the original. I think that is what someone is doing. Preferably with a dynamic, master list of all the gauges by name, and supporting parent/child relationships between gauges so that you can switch on and off the toplevel gauges, or change their colors, and their children will switch on/off, or scale their colors back accordingly.

That reduces the amount of work to making HUD gauges work for RTT or scripting to coding things in for that one HUD gauge class, and then letting the individual gauges override the draw functions where needed to draw that gauge properly. The draw function would probably take something like a texture index, and then optional UV coords, so you could map each gauge to a texture or multiple gauges to one texture (to minimize rendering time).

One thing to note is that the HUD may be dependent on the viewer. If you want working 3D cockpit gauges you might not want to be locked in to assuming that the viewer object is the one drawing the HUD. Or you might want to draw the radar from another ship for cinematic effect, or maybe for some special mission gimmick (receiving radar or visual feed from a spy ship, for example).
Title: Re: Full color HUD
Post by: portej05 on January 06, 2009, 12:13:08 am
Alrighty, I'm going to leave this one alone.
Title: Re: Full color HUD
Post by: WMCoolmon on January 06, 2009, 03:17:00 am
Alrighty, I'm going to leave this one alone.

 :(