Bitmap font engine problem

Started by
21 comments, last by Jason Z 11 years, 1 month ago

Wow, I accidentaly found a perfect article, describing the process I tried to explain in my previous post biggrin.png

Hope it will help someone who stuck at this problem just like me.

It describes how you must subtract 0.5 to get corresponding pixel and texel match each other.

That is not correct in D3D11, only in D3D9. It has changed. If that fixes your problem then it is coincidental and not your actual issue, as you see from the letters that still look wrong.

You should divide by 1900 to get correct coordinates if that is the size of the texture, not 1899. The last pixel begins at 1899, but ends at 1900.

Imagine a texture that is just 1x1 or 2x2 in size. If you divide by width-1 you get completely wrong results.

If your Q begins at 795 and is 9 pixels wide then the correct coords are:

795.0 / 1900.0 = 0.4184210526

(795.0 + 9.0) / 1900.0 = 0.4231578947

If you have a 1x1 sized letter at the last pixel on the right side of the texture, then it starts at 1899 and has a width of 1.

1899.0 / 1900.0 = 0.9994736842

(1899.0 + 1) / 1900.0 = 1.0

Each single pixel is a quad with 4 edges, it is not a zero-width point. Each single pixel has a width of 1.0 / 1900.0

Advertisement

Wow, I accidentaly found a perfect article, describing the process I tried to explain in my previous post biggrin.png

Hope it will help someone who stuck at this problem just like me.

It describes how you must subtract 0.5 to get corresponding pixel and texel match each other.

That is not correct in D3D11, only in D3D9. It has changed. If that fixes your problem then it is coincidental and not your actual issue, as you see from the letters that still look wrong.

You should divide by 1900 to get correct coordinates if that is the size of the texture, not 1899. The last pixel begins at 1899, but ends at 1900.

Imagine a texture that is just 1x1 or 2x2 in size. If you divide by width-1 you get completely wrong results.

If your Q begins at 795 and is 9 pixels wide then the correct coords are:

795.0 / 1900.0 = 0.4184210526

(795.0 + 9.0) / 1900.0 = 0.4231578947

If you have a 1x1 sized letter at the last pixel on the right side of the texture, then it starts at 1899 and has a width of 1.

1899.0 / 1900.0 = 0.9994736842

(1899.0 + 1) / 1900.0 = 1.0

Each single pixel is a quad with 4 edges, it is not a zero-width point. Each single pixel has a width of 1.0 / 1900.0

Oh, thanks for clearing that up for me. Now I have everything working as intended! =)

Concerning GDI. Thank you for pointing that out for me, but I hope to use the same text class I'm creating right now in 3D world as well. As far as I understand, GDI is used for 2D text rendering on the window surface (standard Win32 graphics API). The code of Hieroglyph 3 is extremely well written, but it's a little overwhelming project for me as beginner =) That's why I'm trying to create very simple font rendering engine the same way as described in Rastertek tutorial.

Thanks for the compliment :) I know you already solved the problem, but just for clarification about this point: GDI is indeed a 2D text rendering technology. However, Hieroglyph uses GDI to generate the 2D texture, similar to what you are doing manually. This generated texture (I guess it would be called a glyph texture) can then be used in 2D rendering like what you are doing now, or in 3D as well. Both methods are currently supported in Hieroglyph via the SpriteRendererDX11 (for 2D) and TextActor (for 3D).

If you ever have any questions about Hieroglyph, please feel free to shoot me an IM and I would be happy to help.

This topic is closed to new replies.

Advertisement