Jump to content
  • Advertisement
Sign in to follow this  
Headkaze

Using texture matrix for texture atlas

This topic is 2813 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 want to use GL_UNSIGNED_SHORT for my texture coordinates (in pixels) but because I am using texture atlasses I need to modify the texture matrix rather than loop through all the vertex data and change the uv coords everytime I need to change the model's skin.

Say "imageRect" holds the dimentions of the image in the texture and textureSize is the size of the texture. Below is currently how I am setting the texture matrix but I am not getting the area of the texture I expect.

glMatrixMode(GL_TEXTURE);

glLoadIdentity();

glTranslatef(1.0f / m_imageRect.x, 1.0f / m_imageRect.y, 0.0f);
glScalef(1.0f / m_imageRect.width, 1.0f / m_imageRect.height, 1.0f);

glMatrixMode(GL_MODELVIEW);


Any ideas?

Share this post


Link to post
Share on other sites
Advertisement
What are you getting? Is the resulting image stretched? Is it the right size, but coming from the wrong location? Is the y coordinate in m_imageRect relative to the top or bottom of the image, and how does that compare to the texture matrix translation?

Share this post


Link to post
Share on other sites
The following works

glScalef(1.0f / textureSize.width, 1.0f / textureSize.height, 1.0f);
glTranslatef(m_imageRect.x, m_imageRect.y, 0.0f);


Although I have to multiply my texture coords by 2.0f for some reason.

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!