Sign in to follow this  
SKonen

Texture Offsets

Recommended Posts

SKonen    122
I'm in the process of expirementing with the creation of a C++ 2D engine and am having some fustrations dealing with texture offsets for sprites. Currently I'm loading a texture from an image which has four 32x32 boxes in a row (128x32). Then jumping down the road abit I set the texture coordinates for a square like this: left = (1.0f/fFullTextureWidth)*(float)m_rectTexture.left; right = (1.0f/fFullTextureWidth)*(float)m_rectTexture.right; So for example if the texture width is 128 and m_rectTexture.left is 32 and m_rectTexture.right is 64, left will be 0.5 and right will be 0.75. This all works perfectly for the sprites with a scale of x = 1, y = 1. But if I change it to say: 1.5 and 1.5, I get a vertical line of 1 pixel width from the previous 32x32 square. Stangely, if I set x scaling to 1.5, and y to 1, it'll work just fine without any "bleeding". Various scalings will work fine such as 2 and 2, but others won't. How do I fix this? Is there a way to "bind" the UV coordinates to ensure nothing outside of them is used (though I thought that was the entire point of UV coordinates). Thanks in advance. If I get a really helpful answer, I may be willing to "donate" some funds ;)

Share this post


Link to post
Share on other sites
Cambo_frog    855
The 1 pixel out thing sounds like the "Directly Mapping Texels to Pixels" problem.
Search on "Directly Mapping Texels to Pixels" in the SDK help file.

HTH,
Cambo_frog

Share this post


Link to post
Share on other sites
Drakex    273
It might also have to do with texture filtering. Try setting the sampler states' min/mag filters to point. Only problem is then the sprites look kind of "pixelated" when scaled.. hmm..

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