Reputation: 1
When I have multiple textured quads that use the same texture but at different coords the textures get morphed. Here's what my code looks like:
glBindTexture(GL_TEXTURE_2D, texture_id);
glBegin(GL_QUADS);
glVertex2f(0, 0); glTexCoords2f(0, 0);
glVertex2f(32, 0); glTexCoords2f(.5, 0);
glVertex2f(32, 32); glTexCoords2f(.5, .5);
glVertex2f(0, 32); glTexCoords2f(0, .5);
glEnd();
glTranslatef(32, 0, 0);
glBegin(GL_QUADS);
glVertex2f(0, 0); glTexCoords2f(.5, .5);
glVertex2f(32, 0); glTexCoords2f(1, .5);
glVertex2f(32, 32); glTexCoords2f(1, 1);
glVertex2f(0, 32); glTexCoords2f(.5, 1);
glEnd();
Does anybody know what causes this and how to fix it?
Upvotes: 0
Views: 153
Reputation: 35933
You're calling glTexCoord and glVertex in the wrong order. glVertex should always be the last attribute called to complete a vertex.
Should be:
glBegin(GL_QUADS);
glTexCoords2f(0, 0); glVertex2f(0, 0);
...
Upvotes: 1