How to handle HUD sub-pixel alignment?

All about the core api and animation, input, sound, effect, collision and physics engines.
You can also post here your feature requests.

Moderator: Brume Dev Team

How to handle HUD sub-pixel alignment?

Postby jeskeca on Thu Apr 10, 2008 1:25 am

The HUDX/HUDY convinent functions are nice, however, they don't correctly address subpixel alignment necessary because of even or odd sized textures and the fact that the BrumeSquareTextured mesh is middle-centered.

For example, if you use the simple example code to create a HUD logo, it uses a 100w 45h texture. Because the width has an even number of pixels, and the (0,0) position of this texture is the middle, it falls between two pixels horizontally, causing all vertical lines to be blurred across two pixels.

here is a screenshot for example:

ex1_blurry.png


Here is the code used to render the fragment.

Code: Select all
BrumeSquareTextured logo = new BrumeSquareTextured(this, "Brume logo");
BrumeTexture texture = new BrumeTexture(this, "logo test",100, 45, 1, BrumeTextureParams.FORMAT_X8R8G8B8);
            Graphics gc = texture.GetGraphics();
gc.DrawString("GDI Test", new Font(FontFamily.GenericSansSerif, 10.0f), Brushes.White, 0, 0);
gc.DrawLine(new Pen(Color.White), 0, 45 / 2, 100, 45 / 2);
gc.DrawLine(new Pen(Color.White), 100 - 4, 0, 100 - 4, 45);
texture.ReleaseGraphics();
logo.RenderStates.Lighted = false;
logo.RenderStates.Texture[0] = texture;
logo.RenderStates.Perspective = BrumeRenderParams.PERSPECTIVE_HUD;
logo.RenderStates.AlphaBlending = BrumeRenderParams.ALPHABLENDING_TEXTUREALPHA;
logo.HasGlobalSize = false;
logo.XSize = 100.0f;
logo.YSize = 45.0f;
logo.Pos.X = HUDX(this.BrumeWidth - 60);
logo.Pos.Y = HUDY(this.BrumeHeight - 40);


Are there any recommendations on how to handle HUD items so this does not occur?

Right now I'm going to make a BrumeSquareHudTextureMesh which has (0,0) as the upper-left coordinate of the mesh, instead of putting (0,0) in the center of the square. Is this the approach others use?
jeskeca
Brume Rookie
 
Posts: 17
Joined: Wed Apr 02, 2008 4:52 pm

Re: How to handle HUD sub-pixel alignment?

Postby Silmaryls on Mon May 19, 2008 8:23 pm

Well I think there are no recommendations for that problem apart of fixing it ! :D
I am quite sure you are the first that noticed that alignment problem.
I will take a look at it.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France

Re: How to handle HUD sub-pixel alignment?

Postby Silmaryls on Sat May 31, 2008 11:49 pm

Hi again,

I made some tests and I think that you should always deal with your "special alignment cases".
I will add directx half pixel alignment correction for next release but it will not solve your problem.
As you said, the quad coordinates may be shifted in the wrong way depending on the quad size.
But HUDX and HUDY are just "helpers" and these methods have no alignment policy as it depends on the users shape (in fact, it will be better to create a new mesh with screen space coordinates).
So the best solution (In my opinion) is to avoid special cases by using adapted quad/texture size or by adding 0.5f yourself to the axis that is not aligned correctly.
User avatar
Silmaryls
Brume Team Member
 
Posts: 340
Joined: Tue Feb 21, 2006 10:09 pm
Location: Paris - France


Return to Technical discussion

Who is online

Users browsing this forum: No registered users and 1 guest

cron