Advertisement

Characters being offset by a pixel in BMFont

Started by June 01, 2015 12:47 AM
3 comments, last by judeclarke 9 years, 5 months ago

I am looking for help on what seems to be a simple issue, but after comparing how the shaders and vertex buffers are identifical, I am baffled as to the problem. I have been trying to get the BMFont format to render with DirectX11 and while it is just about working, there is one minor yet major issue left. In the example below, the "e" and the "a" are offset by one pixel to the left, and one pixel up on the y. The s, t and n are all fine though. I compared the two vertex buffers and they are identical for the values in the x,y,z,u,v, channel in both running applications. I am hoping that this issue will seem familiar with the issue.

Enlarged image

offsetenlarged.png

Original image

offsetoriginal.png

They are also using the same .fnt and texture file. I seem to have the same issue even if the text was "estna", without the first t.

What is the difference between the two applications?

By the looks of the output, I have a feeling it may have something to do with the sampling of the font texture. Are you perhaps using point-sampling, i.e. no interpolation? Have you set up the transform matrices for pixel-perfect rendering? Specifically check the manual for how to adjust coordinates (if necessary) for pixel perfect sampling. It might be that you need to add (0.5,0.5) texels to the UV coordinates to get the best result.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

You were correct, I was setting the sampler to be point but it was eventually being changed. Fixing this seems to expose one final issue I am having, which is that the text will be displayed "blurry", which can be seen here. I made sure I am using the same sampler as the example was using.

offsetenlargedblurry.png

This blurriness with the interpolated samples, plus the fact that it was almost correct with point sampling, tells me that you're likely getting samples that are offset by (0.5,0.5) texels, thus each pixel will be rendered as an average of the 4 nearby texels.

Try adjusting the UV coordinates with (0.5,0.5) texels, or perhaps the screen coordinates with (0.5,0.5) pixels.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I removed the .5 additions to the u and v and now everything works, thank you

This topic is closed to new replies.

Advertisement