Using texture matrix for texture atlas

Started by
1 comment, last by Headkaze 13 years, 3 months ago
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?
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?
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.

This topic is closed to new replies.

Advertisement