2D texturing issue

Started by
4 comments, last by BradDaBug 15 years, 6 months ago
I'm pretty new to D3D, but I recently decided to add a D3D renderer to my game in addition to the OpenGL renderer it already had. I've got them rendering everything almost identically, except for this weird issue with some of the GUI stuff. Take a look: OpenGL screenshot The OpenGL version. See how crisp and clean everything is? Direct3D screenshot The Direct3D version. See how fuzzy the text is, and the black ring around the radar thingy? I've tried to keep the two renderers' code as similar as possible, and in many cases they're using exactly the same code. I'm doing the 2D projection stuff inside a simple Cg shader that both the D3D and OpenGL renderers use. Any other ideas about what could cause this?
I like the DARK layout!
Advertisement
In D3D9 and below, the rasterization rules are different from OpenGL. Offset your UVs by half a pixel. (ie: instead of 40.0f/texsize use 40.5f/texsize).
Hey, that actually seems to work. Though now the text looks a little funny, like edges of the neighbor characters on the font texture are being printed along with the correct character.
yay

What exactly is different between D3D and OpenGL in this case? The docs say that D3D considers 0 to be the pixel at one edge of the texture and 1.0 to be the pixel at the opposite edge, which (iirc) is the same way OpenGL works, so why is the half-pixel offset needed?
I like the DARK layout!
Quote:Original post by BradDaBug
Hey, that actually seems to work. Though now the text looks a little funny, like edges of the neighbor characters on the font texture are being printed along with the correct character.
yay

What exactly is different between D3D and OpenGL in this case? The docs say that D3D considers 0 to be the pixel at one edge of the texture and 1.0 to be the pixel at the opposite edge, which (iirc) is the same way OpenGL works, so why is the half-pixel offset needed?
I can't speak for OpenGL, but with D3D, 0.0f is the left edge of the leftmost texel, 1.0f is the rightmost edge of the rightmost texel.

If you have a 2x2 texture, it'll be like so:
(0.0, 0.0)   +----------+----------+   |          |          |   |    X     |          |   |          |          |   |          |          |   +----------+----------+ (1.0, 0.5)   |          |          |   |          |          |   |          |          |   |          |          |   +----------+----------+         (0.5, 1.0) (1.0, 1.0)

The point marked X has texture coords (0.25, 0.25), so if you want to use that texel you need to use (0.25, 0.25) as your UV coords. If you use 0.0, then you'd get the edge of the next texel (If the texture is wrapping).

Something else to check (Although I'm pretty sure it'll be correct) is that you're using AdjustWindowRectEx to get the correct client area size from the window size, since CreateWindowEx takes the size of the window, not the client area, and not adjusting for that will cause the backbuffer to be shrunk to fit the client area.

Also, you could try the reference rasterizer, in case it's a weird driver bug.

EDIT: Also, off topic - it's a good idea to post images as PNG rather than JPEG when you're talking about pixel issues like this, JPEG is lossy and causes some oddness around colour edges.
This explains it.
That does explain it.

I got it working perfectly! Thanks!
I like the DARK layout!

This topic is closed to new replies.

Advertisement