Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Issue with bitmap based HUD

Author
Message
Pisces
20
Years of Service
User Offline
Joined: 6th Oct 2005
Location:
Posted: 2nd Dec 2010 06:14
So I want to make a hud at the bottom of my screen that I can update if and when I want it to. I will also have clickable buttons on the hud. Right now I am focusing on getting the frame to display correctly.



Bitmap is not declared in the main code, function is run in the initial and the main loop. Global variable hudtimer is defined in the starting code as 10000 so it triggers on first run. My hud image is 800x600 of which I want the bottom 800x150. It will occupy the same space in my screen.

The first time the function runs it works fine... displays my hud perfectly. The second time it runs it stretches, crops and blurs the image so I can only see the topleftmost portion. Note I know a lot of the commands are not necessary, I added them to eliminate possible causes with no effect.

*insert witty dark basic comment here*
DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 2nd Dec 2010 14:01
Hmm, not sure from that snippet. I wouldn't load the image on the fly if I were you. Is the image you load up each time the same? Or are you saving it somewhere else in the program? I would load it once and once only. Loading up the image all the time is a real hog and from what I can see a waste of time. What sort of HUD is it?

http://s6.bitefight.org/c.php?uid=103081
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Dec 2010 18:05
Why are you reloading the image constantly in the main loop?

And hudTimer isn't going to work like you want unless it's been defined global. It's also in inaccurate way to configure a time delay since it'll be based on cpu ticks and thus subject to fluctuate on different machines.

"Only the educated are free" ~Epictetus
"Imagination is more important than knowledge..." ~Einstein
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 2nd Dec 2010 18:07 Edited at: 2nd Dec 2010 18:08
Without running it it's probably:



You don't have a texture flag of 1 so every time this image is grabbed it's going to be blurry.



DVader is right (of course ). You should instead load the blank hud as an image once (at the top of your code) then use PASTE IMAGE to the bitmap when you want to update your hud. You also don't need to grab the entire screen if you're only using the bottom 150 pixels. You can create the bitmap exactly the size of your hud, grab just that as the image, and use the image where you want. If you do this a lot I would recommend not deleting the bitmap every time... just leave it as is so you don't have to re-create it every 5 seconds. Using PASTE IMAGE will basically clear the bitmap every time no matter what is on the bitmap previously.

We use BITMAPs when we want to edit the image and grab the edited results but it doesn't even look like you need to create a bitmap at all since you don't really modify the image. All that code does is loads the image to regrab it with GET IMAGE. Just use LOAD IMAGE to keep that image in memory so you don't have to reload it all the time and use PASTE IMAGE when you want to see it on the screen (or use SPRITE).

Pisces
20
Years of Service
User Offline
Joined: 6th Oct 2005
Location:
Posted: 2nd Dec 2010 19:47
Thanks all for the quick responses.

It is a HUD for a turn based strategy game, so I will need clickable buttons and info that changes depending on where your mouse is along with what unit/territory you have selected.

So if I want the the HUD to update I don't need to re-get the image? Also, no the hud doesn't update in the above code... I am trying to get it working before I tell it what kind of updates to make.

In reference to hudtimer... does the "timer" command work better? I thought about using it, but I didn't know if it would pick up the total run time of the program or the time between loops.

Adding the 1 as the texture flag worked great! Thanks. While I am here, any suggestion for putting info on my HUD? The text command only seems to work with strings.

*insert witty dark basic comment here*
Grog Grueslayer
Valued Member
21
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 3rd Dec 2010 02:57
Quote: "So if I want the the HUD to update I don't need to re-get the image? Also, no the hud doesn't update in the above code... I am trying to get it working before I tell it what kind of updates to make."


You still use GET IMAGE you just don't load the blank HUD image over and over again or delete the bitmap... everything is reusable.

Quote: "In reference to hudtimer... does the "timer" command work better? I thought about using it, but I didn't know if it would pick up the total run time of the program or the time between loops."


Technically you should only update the HUD if there's a change in information (more Cash or whatever). If it's on a timer and there is no change it's a pointless waste of time to update the HUD if it's going to look exactly the same after the update. I added a timer to the following code snip to show you what a timer would look like.

Quote: "Adding the 1 as the texture flag worked great! Thanks. While I am here, any suggestion for putting info on my HUD? The text command only seems to work with strings."


To use the TEXT command with variables use the STR$() command to convert the variable to a string.

Here's an example HUD using your image (changed to a .png that's attached):



Pisces
20
Years of Service
User Offline
Joined: 6th Oct 2005
Location:
Posted: 3rd Dec 2010 06:27
Thanks Grog.

I figured out the str$() pretty soon after posting, but the hud code is great!

Is there an advantage to .png over bmp? I may need to make my humongous map of new york a bitmap at some point...

*insert witty dark basic comment here*
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 3rd Dec 2010 15:37
.PNG is usually compressed - but probably not as well compressed as .JPG because they are lossless - meaning you don't loose visual quality with compression. It's the best format usually for all sorts of things. Mainly though, that is because they support alpha transparency - I'm sure your gonna be concerned with that soon, so I suggest switching to .PNG as soon as you can.

One thing that annoys me with HUD's is the amount of waste - I'm guessing you have a HUD designed, or going to be designed as a whole screen, with a cut out in the middle. The issue with that is that you end up with a massive area of alpha transparent texture, being drawn - even though there's nothing to actually draw. Plus you have the limit to display resolution, because if you try viewing that 800x600 hud at a high resolution it'll look rubbish, no matter how much time you spend on it. What I would do, is make a HUD object, and texture it properly - so you'd still have the border, and a blank area in the middle, but you could use that for other things - like little doors on your HUD, bits here and there - or a text font if you like. Anyway - that does away with a few of my concerns because it's resolution independant - but also that are in the middle that would usually be drawn, can be skipped, you could just have the border and hud menu etc and leave the 'window' blank. Personally I would go for that technique every time - and even try and make an alternative version for wide screen displays. Doing that in 2D is very tricky, doing it in 3D is easy so long as you can model basic shapes. The 3D HUD does not need to be complex - because you could easily do it all in the texture - the main thing is to get rid of the 'window' so it doesn't have to be drawn.

There's lots you can do in 3D that are just not feasible any other way. For example, I like authentic score displays - in one game I had a flip down clock, like little pages that flip down like the hatch clock from LOST, in another game I made a tape style counter, the barrel type where the numbers spin around. It takes a while to plan these things and get them prepared - but really when coding them, it's no more complex than standard score displays. If I was making an RTS game, I'd have a field day with proper 3D compass, money counter, buttons, lights etc etc. RTS games are so far removed from the actual action, I think it would be cool to have a really tangible and functional HUD.

Health, Ammo, and bacon and eggs!
Pisces
20
Years of Service
User Offline
Joined: 6th Oct 2005
Location:
Posted: 3rd Dec 2010 19:22
I initially started this project in 3d, but ran into issue after issue (mostly with selecting objects with my mouse). I decided to go 2d because it eliminated that third dimension that was giving me problems. Also, I am wary of biting off more than I can chew - I can do everything I need to do, but theres just one of me... and I have a day job. I want to get this thing filled out before I start adding frills.

*insert witty dark basic comment here*
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 6th Dec 2010 00:07
Regarding the "window" problem VanB... I would have assumed the common solution here, is what I've always envisioned building a HUD to be like - and seen this is a few commercial games whose assets I've had the chance to browse through in the past.

Do your HUD in your image program or w/e but then export it as sliced images, and then load and position those images on the screen as individual pieces to build the final image.

It seems to me, in that way the only obstructed parts of the camera are the parts the HUD elements are placed at, and there is no need to worry about one huge image with a transparent section being rendered, etc.

DVader
22
Years of Service
User Offline
Joined: 28th Jan 2004
Location:
Posted: 7th Dec 2010 17:12
I tried that a while ago on a small test app I made. I seem to remember it being a fair bit faster. It was intended for a net book so every little helped.

http://s6.bitefight.org/c.php?uid=103081
Mobiius
Valued Member
23
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 7th Dec 2010 19:49
You could do what I do and load images in a screen size independent way.

I create my HUDS / Menus with a self made XML file...

As you can see, each UI element, (A button for example) has it's own info. The Size and Pos variables are percentages of the actual screen size. (So 50.0 becomes 50.0%, I.E. the center of the screen)

this has the advantage of ensuring that all menus/huds will look the same for each screen aspect, (4:3 will look different to 16:9 due to the horizontal size being bigger) but this is something I can live with.

I wrote a simple parser using IanM's matrix utils, (specifically, the split string commands) which will read in the XML file until it gets to a command it recognises, then uses the values set to it.

Here's a simple excerpt of my parsing code. It won't compile but it provides a start to creating a parser..


My signature is NOT a moderator plaything! Stop changing it!

Login to post a reply

Server time is: 2026-07-21 19:18:51
Your offset time is: 2026-07-21 19:18:51