PDA

View Full Version : Auto texture coord. -- flipped/inverted textures



lsdi
01-27-2002, 09:40 AM
Im doing this to draw texture mapped 2 triangles, but the textures are flipped and rotated, why?






something like this:

2 triangles, size = MAP_SIZExMAP_SIZE
_______
|\ |
| \ |
| \ |
| \ |
| \ |
--------

void draw_simple_quad(int QUAD_ID)
{

glBindTexture(GL_TEXTURE_2D, texture[Terrain[QUAD_ID].texture_id]);
GLfloat sPlane[] = {1.0/MAP_SIZE, 0, 0, 0};
GLfloat tPlane[] = {0,0,1.0/MAP_SIZE,0};

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);

glTexGenfv(GL_S, GL_OBJECT_PLANE,sPlane);
glTexGenfv(GL_T, GL_OBJECT_PLANE, tPlane);

glBegin(GL_TRIANGLES);

glVertex3f(Terrain[QUAD_ID].vertices_x1[0],
Terrain[QUAD_ID].vertices_y1[0],
Terrain[QUAD_ID].vertices_z1[0]);
//glTexCoord2f(1,1);
glVertex3f(Terrain[QUAD_ID].vertices_x2[0],
Terrain[QUAD_ID].vertices_y2[0],
Terrain[QUAD_ID].vertices_z2[0]);
// glTexCoord2f(1,0);
glVertex3f(Terrain[QUAD_ID].vertices_x3[0],
Terrain[QUAD_ID].vertices_y3[0],
Terrain[QUAD_ID].vertices_z3[0]);
// glTexCoord2f(0,0);
glVertex3f(Terrain[QUAD_ID].vertices_x4[0],
Terrain[QUAD_ID].vertices_y4[0],
Terrain[QUAD_ID].vertices_z4[0]);

glVertex3f(Terrain[QUAD_ID].vertices_x5[0],
Terrain[QUAD_ID].vertices_y5[0],
Terrain[QUAD_ID].vertices_z5[0]);
// glTexCoord2f(0,1);
glVertex3f(Terrain[QUAD_ID].vertices_x6[0],
Terrain[QUAD_ID].vertices_y6[0],
Terrain[QUAD_ID].vertices_z6[0]);
glEnd();
}

Bob
01-27-2002, 11:19 AM
Either you load the image wrong, or you use the wrong object planes.

Some images are stored "up side down" in the file, and that might explain why you have a flipped texture. Read some specification on the format you are using to see how toe image is stored.

You can also put a minus sign infront of the '1/MAP_SIZE' in one of the object planes. Which one needs a minus sign depends on how the image is flipped. Try and see what happens.