• Advertisement
Sign in to follow this  

Off-pixel problem rendering bitmapped fonts with ortho projection

This topic is 3861 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Aloha people, I was hoping that some of you wizkids find this question academic and are able to help me out with the following problem. On the engine I'm working on were using bitmapped fonts rendered as quads to display text, stories, descriptions on buttons and other stuff related to 2d-gui elements. So far we have been using orthographic projections to render all 2d elements - the intention has been to bypass the 3d -> 2d calculations which would otherwise be needed using a perspective projection. Also some articles here at gamedev suggests that ortho projections comes to good use in 2d engines. However, on older cards (ti4400) there are problem with half-pixels and the font-rendering looks seriously messy - since the resolution defaults to 800x600 using anything but D3DTEXF_POINT for Min & Mag filter is not an option because it becomes too blurry. Having spend some time debugging this I have verified that both D3DTS_WORLD and D3DTS_VIEW seems sound - all have 1.0f as scale and are placed at integer positions. However D3DTS_PROJECTION would seem to suffer from rounding errors. We are using a standard left-hand orthographic projection calculation: 2/w 0 0 0 0 2/h 0 0 0 0 1/(zf-zn) 0 0 0 zn/(zn-zf) 1 When looking closer at what the result is, using an 800x600 resolution, I notice that 2/w == 0.0024999999 and 2/h = 0.00333333334 - without rounding errors 2/w should equal 0.0025 Now this might seem like a very small rounding error, but currently I'm looking for anything that could explain why my otherwise pr. pixel integer placed quads are displayed off-pixel and messy - since both world and view transformation seems sound and as should be, the small rounding error in projection matrix has caught my eye. Now the question(s): * For you hardcore experienced 3d-veterans, does the above seem like a reasonable explanation to my problem or am I a crazy person? * If this could in fact explain why I have off-pixel renderings does anyone have any suggestions as to what the usual approach of fixing this problem might be? Thanx ;) /placebotge PS. Oddly enough newer cards have no problem displaying the quads properly and without ½-pixel problems

Share this post


Link to post
Share on other sites
Advertisement
I have worked extensively with developing a custom text system using textured quads. I used transformed coordinates but the orthographic approach is the same thing, basically. I don't, however, necessarily have 'pixel perfect' results; I don't even know what that means, exactly, since your app could ultimately be running on a wide variety of graphics adapters and resolutions.

Can you give us a screenshot of the problem? The first thing -I- would check is the mipmap setup for your font texture. Using different mip levels give different results depending on the ratio between the target resolution and your font texture. I used a fairly large font texture (64x64 per character) and found D3D's mipmap chain to be unacceptable; depending on what I want I either disable mipmapping altogether or manually generate the smaller images used to render small text. But then again, you're insisting on using point sampling (which I think is suboptimal in almost all cases, 2D or 3D) so this might not apply to you. You can definitely get pretty good looking results WITH point sampling even at 800x600.

Are you sure this is a math problem (texture coordinates off by 0.5, etc.) and not a rendering issue?

Share this post


Link to post
Share on other sites
Thank you, the both of you.

This morning it dawned on me that I had other quads (non-text) being rendered with the same camera, and hence the same projection matrix, which with some quick debugging turned out to be rendered pixel-perfectly.

The problem had to be elsewhere.

Demirug - Thank you very much for posting that! This was exactly what was wrong.

*Blush* - <Directly Mapping Texels to Pixels> - I have both read and scanned that particular page in the dxut help document several times, but until now I havent clearly understood the essence of it - I've even seen other posts where this has been the answer, but thinking this was not the cause of _my_ problem. Somehow having the link posted in my own face made me closely read it and gave the necessary "heureka" moment.

With regard to my own definition of "pixel perfect" I should clarify I meant a 1:1 relationship between what the texture contains and what is rendered into the backbuffer (ie. having a texture with alternating black and white dots should produce exactly that onto the backbuffer)

The engine is used for 2d-casual games where the defacto-standard resolution more or less is a resolution of 800x600 - the target audience of 35+ women are not exactly picky when it comes to resolutions. This is also the reason why we use relatively small fonts and do not use any kind of Min/Mag filtering (at least for fonts and other gfx that needs to be crisp) and that a 128x128 texture normally can contain an entire font instead of just a character.

Once again, thanx to both of you for your answers.

/placebotge

Share this post


Link to post
Share on other sites
Quote:
Original post by placebotge
The engine is used for 2d-casual games where the defacto-standard resolution more or less is a resolution of 800x600 - the target audience of 35+ women are not exactly picky when it comes to resolutions.

Interesting; I have been making games for RealArcade (puzzle games for generally older women, sound similar to your project) and they told me to start up in at least 1024x768, and my latest project will just run in whatever resolution the desktop is in (albeit in fullscreen mode.) Not trying to quibble with you about the fonts, but I didn't know people were still worried about 'pixels' in the casual games market anymore...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement