Textures are flipped/inverted

Im using this code to auto-generate coords for texture mapping, but the textures are drawn inverted/flipped why?

void draw_simple_quad(int QUAD_ID)
{
glBindTexture(GL_TEXTURE_2D, texture[Terrain[QUAD_ID].texture_id]);
GLfloat tPlane = {1.0/MAP_SIZE, 0, 0, 0};
GLfloat sPlane = {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);
glTexCoord2f(0,0);
glVertex3f(Terrain[QUAD_ID].vertices_x1[0],
Terrain[QUAD_ID].vertices_y1[0],
Terrain[QUAD_ID].vertices_z1[0]);
glTexCoord2f(1,0);
glVertex3f(Terrain[QUAD_ID].vertices_x2[0],
Terrain[QUAD_ID].vertices_y2[0],
Terrain[QUAD_ID].vertices_z2[0]);
glTexCoord2f(1,1);
glVertex3f(Terrain[QUAD_ID].vertices_x3[0],
Terrain[QUAD_ID].vertices_y3[0],
Terrain[QUAD_ID].vertices_z3[0]);
glTexCoord2f(0,1);
glVertex3f(Terrain[QUAD_ID].vertices_x4[0],
Terrain[QUAD_ID].vertices_y4[0],
Terrain[QUAD_ID].vertices_z4[0]);
glTexCoord2f(0,0);
glVertex3f(Terrain[QUAD_ID].vertices_x5[0],
Terrain[QUAD_ID].vertices_y5[0],
Terrain[QUAD_ID].vertices_z5[0]);
glTexCoord2f(1,1);
glVertex3f(Terrain[QUAD_ID].vertices_x6[0],
Terrain[QUAD_ID].vertices_y6[0],
Terrain[QUAD_ID].vertices_z6[0]);
glEnd();
}

Some image formats stores the image from bottom to top, while other stores them from top to bottom. Without knowing what format you use, I can say that BMPs are stored bottop up, and so a most TGAs. Also remember that OpenGL has the origin in the lower left corner. That means that texture coordinate (0,0) is the lower left corner of the image. This can also cause some confusion.