Jump to content
  • Advertisement
Sign in to follow this  

Texture atlas and clipping rectangle

This topic is 1125 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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!