Sign in to follow this  

Texture atlas and clipping rectangle

This topic is 823 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

I was wondering how do you properly do a clipping rectangle for a texture atlas?

Recently I have had issues with my texture atlas and clipping rectangles. For some reason the sprites I render occasionally are distorted. They are stretched in some way, either on the X and Y axis.

For example I use a clipping rectangle for my animations. I have an animation for a waving flag. When I need to change the animation's frame I just move the clipping rectangle. Unfortunately, on some frames it looks like the flag is growing/shrinking even though the animation does not have this. Its seems like it is due to the issue above

What is going on? I believe that its due to my UV coords. I am setting my texture coords like this, all calculations are using floats, my projection matrix is scaled at 1.5, and my frag shader uses mediump for its uv coords
 

uv top left x: clipRect.x / texture.width
uv top left y: clipRect.y / texture.height

uv top right x: (clipRect.x + clipRect.width) / texture.width
uv top right y: clipRect.y / texture.height

uv bot left x: clipRect.x / texture.width
uv bot left y: (clipRect.y + clipRect.height) / texture.height

uv bot right x: (clipRect.x + clipRect.width) / texture.width
uv bot right y: (clipRect.y + clipRect.height) / texture.height
Edited by noodleBowl

Share this post


Link to post
Share on other sites

This topic is 823 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.

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