Page 1 of 1

How to handle HUD sub-pixel alignment?

PostPosted: Thu Apr 10, 2008 1:25 am
by jeskeca
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?

Re: How to handle HUD sub-pixel alignment?

PostPosted: Mon May 19, 2008 8:23 pm
by Silmaryls
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.

Re: How to handle HUD sub-pixel alignment?

PostPosted: Sat May 31, 2008 11:49 pm
by Silmaryls
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.