Sign in to follow this  
BradDaBug

OpenGL 2D texturing issue

Recommended Posts

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?

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this