HUD rendering on different screen sizes

Status
Not open for further replies.

Lach

he/him
Sonic Team Junior
Kart Krew™️
Judge
I'm trying to place an icon on the screen using Lua whenever a certain player variable is active. In green resolutions it works fine, but of course in non-green resolutions it strays from its intended placement due to the way SRB2 handles different aspects.

I subtracted values from v.width() and v.height() to try and circumvent the problem, but for some reason it renders off the screen in many resolutions, including green ones. I thought perhaps they were scaled values, so I divided by v.dupx() and v.dupy() respectively, which worked in green resolutions, but in others actually rendered the icon on the opposite side of the screen. If they don't return your screen size, what do v.width() and v.height() actually return? And how do I use v.dupx() and v.dupy()?
 
If you just want to snap HUD items to the sides / top / bottom of your screen, V_SNAPTOLEFT, V_SNAPTORIGHT, V_SNAPTOBOTTOM and V_SNAPTOTOP should be of assistance, but these are pretty weird with how they handle stuff sometimes. (You won't ever be able to get something properly displaying accordingly to the SCORE/TIME/RINGS HUD in any resolution other than green)

v.width and v.height do return the actual screen size in pixels, meaning v.height in 1920x1080 will return 1080 (which is of course gonna be off the 320x200 base resolution SRB2 uses for HUDs).
That's where dupx and dupy basically become useful, these are scales used to draw HUD items properly depending on your resolution. You just have to divide v.width and v.height with the proper v.dup variable to get a screenheight/width value you can use for HUD drawing.
Code:
local screenwidth = v.width()/v.dupx()
local screenheight = v.height()/v.dupy()
If you drew a HUD at (screenwidth/2, screenheight-20), it would draw a HUD on the on the horizontal middle of the screen, and 20 units above the screen's bottom. But if you do that, avoid using SNAPTO flags since they will mess furhter with the display.

Hopefully my post made sense.
(Also anyone feel free to correct me if I fucked up completely in my explanation / got things wrong.)

TL;DR:
v.height() and v.width() return screen size in PIXELS
v.dupx() and v.dupy() are scales which are used to position the HUD items depending on the resolution. They have a different value for about each resolution. Dividing v.height by v.dupy and v.width by v.dupx returns values you can use to draw your HUD item properly without having to use SNAPTO flags.
 
Last edited:
(You won't ever be able to get something properly displaying accordingly to the SCORE/TIME/RINGS HUD in any resolution other than green)

...Ah, just checked the source code, and apparently the SCORE/TIME/RINGS part of the HUD use V_NOSCALESTART rather than the V_SNAPTO* flags. V_NOSCALESTART just means the starting position isn't scaled accordingly with the resolution but instead acts as if it were the default 320x200, which means it'll be closer to the top left corner in big resolutions.

This info may or may not be useful, I don't know really.
 
I thought perhaps they were scaled values, so I divided by v.dupx() and v.dupy() respectively, which worked in green resolutions, but in others actually rendered the icon on the opposite side of the screen.

The issue I'm experiencing is that the screen width, height, and respective dup values are all yielding inconsistent results, even when divided. I can't seem to get any icon to appear the same number of pixels away from the right edge of the screen in all resolutions.
 
V_NOSCALESTART may be just what you want then, Lach. When you set that flag the coordinates won't be scaled to a 320x200 base resolution, you can have to do that yourself if needed. Another thing that might help is that v.dupx() and v.dupy each have a second return value, which is just the first one in a fixed_t form. You can then multiply your 320x200 based coordinate or coordinates with them using FixedMul(y*FRACUNIT, fixeddupy) to get one that is scaled, or you can just do vid.width()-distance to get a location that's always distance pixels from the right edge or something.

Note that V_NOSCALESTART stops the V_SNAPTO* flags from working, not that you'd need them anyway.
 
Last edited:
Status
Not open for further replies.

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)

Back
Top