Jump to content


font texture artifacts

c++ directx

5 replies to this topic

#1 Snoob

    Member

  • Members
  • PipPip
  • 42 posts

Posted 02 January 2013 - 11:05 PM

I've implemented a FreeType font renderer. Using OpenGL anything looks like expected, but when I try to render same text with Direct3D9 i got some texture artifacts.
The text looks like cut of at bottom and some letters contains texture fragments at the border edges:

http://s7.directuplo...7c6y54l_jpg.htm Test text rendered with OpenGL
http://s1.directuplo...2ksd9fy_jpg.htm Test text with artifacts rendered with Direct3D9

I use Bilinear filtering (linear/linear/point) and set UV texture addressing mode to CLAMP. First I thought there may be addressing failures and also test
WRAP and BORDER, but I got same issues.

The letters I use for text rendering are rendered to an atlas texture. Could it possible I got those artifacts while I do not use padding space between
the lettes in this atlas texture? If it so, why only on D3D9? Any ideas what could be wrong?

#2 Reedbeta

    DevMaster Staff

  • Administrators
  • 5309 posts
  • LocationSanta Clara, CA

Posted 02 January 2013 - 11:56 PM

Seems like you may be getting bitten by the infamous half-texel offset of D3D9. See this MSDN article for details - the upshot is you have to adjust your UVs by half a texel to make them line up correctly with screen pixels. In D3D10-11 they fixed this so it works the same way as OpenGL does (also known as the correct way. :D)
reedbeta.com - developer blog, OpenGL demos, and other projects

#3 Snoob

    Member

  • Members
  • PipPip
  • 42 posts

Posted 03 January 2013 - 12:45 PM

Thanks for your advise. I've to check this.

#4 Snoob

    Member

  • Members
  • PipPip
  • 42 posts

Posted 03 January 2013 - 08:25 PM

As promised I've checked your advise and it solves the problem! Reedbeta thank's again for your help, you protect me from sleepless nights ! :D
Just one more question concerning to the half-texel offset:

I have read a couple of articles that describe the necessity to move the texture one half unit of the vertex positions in order to get the correct mapping between texels and pixels. According to DirectX documentation, offsetting by half a pixel is only necessary "when rendering 2D output using pre-transformed vertices". But how I could figure out that I've got pre-transformed vertices? On vertex buffer declaration I do not use the FVF flag. So I get into trouble if I always try to fix the half-texel offset by adding -0.5 to x and y values of the vertices (especially using OpenGL).

#5 Reedbeta

    DevMaster Staff

  • Administrators
  • 5309 posts
  • LocationSanta Clara, CA

Posted 03 January 2013 - 08:59 PM

I think by "pre-transformed" vertices it just means vertices that are in screen space already, such as the quads for text. Another common case is when doing a full-screen pass for postprocessing. When rendering 3D stuff you don't typically have to worry about it.
reedbeta.com - developer blog, OpenGL demos, and other projects

#6 Snoob

    Member

  • Members
  • PipPip
  • 42 posts

Posted 04 January 2013 - 09:09 AM

Screen space only, sounds easy to fix. Thanks again.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users