Texturing looks funky (and not in a good way)

Im trying to texture a maze with a brick wall tag file but when I run it, the bricks are in different directions on different sides of the polygon. Instead of using a cube , I am using a cube with no top or bottom…don’t know if that makes a difference.

here’s the code:

/*** This is where the image is read into array and image is filled ****/
void texture_load()
{
    GLuint texture;
    int width;
    int height;
    GLubyte *data;
    FILE *file;
    
    // open texture data
    file = fopen("wall.tga", "rb");
    
    // allocate buffer
    data = (unsigned char*) malloc(width * height * 4);
    
    // read texture data
    fread(data, width * height * 4, 1, file);
    fclose(file);
    
    // allocate a texture name
    glGenTextures(1, &texture);
    
    // select our current texture
    glBindTexture(GL_TEXTURE_2D, texture);
    
    // select modulate to mix texture with color for shading
    glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
    
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_DECAL);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_DECAL);
    
    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 128, 128, 0, GL_RGB, GL_UNSIGNED_BYTE, 
                 (GLvoid *)data);
    
    // when texture area is small, bilinear filter the closest mipmap
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    // when texture area is large, bilinear filter the first mipmap
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    
    // texture should tile
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
    
    // build our texture mipmaps
    //gluBuild2DMipmaps(GL_TEXTURE_2D, 4, width, height, GL_RGBA, GL_UNSIGNED_BYTE, data);
    
    // free buffer
    free(data);
    
}

and here’s my walls:

void drawWalls(int i,  int j) {

	GLfloat v[][3] = {{i * BLOCK_SIZE, j * BLOCK_SIZE + BLOCK_SIZE, 0},
		{i * BLOCK_SIZE, j * BLOCK_SIZE + BLOCK_SIZE, WALL_HEIGHT},
		{i * BLOCK_SIZE + BLOCK_SIZE, j * BLOCK_SIZE + BLOCK_SIZE, WALL_HEIGHT},
		{i * BLOCK_SIZE + BLOCK_SIZE, j * BLOCK_SIZE + BLOCK_SIZE, 0},
		{i * BLOCK_SIZE, j * BLOCK_SIZE, 0},
		{i * BLOCK_SIZE, j * BLOCK_SIZE, WALL_HEIGHT},
		{i * BLOCK_SIZE + BLOCK_SIZE, j * BLOCK_SIZE, WALL_HEIGHT},
		{i * BLOCK_SIZE + BLOCK_SIZE, j * BLOCK_SIZE, 0}};

	polygon(v[0], v[3], v[2], v[1]);
    polygon(v[2], v[3], v[7], v[6]);
    polygon(v[4], v[5], v[6], v[7]);
    polygon(v[0], v[1], v[5], v[4]);
}

void polygon(GLfloat* a, GLfloat* b, GLfloat* c, GLfloat* d)
{
    //glGenTextures(1, &texture);
    //glBindTexture(GL_TEXTURE_2D, texture);
    glEnable(GL_TEXTURE_2D);
    glBegin(GL_POLYGON);
      glColor3f(0, 0, 1);
    glNormal3f(0.0f, 1.0f, 0.0f);
    glTexCoord2d(0.0,0.0);
      glVertex3fv(a);
    glTexCoord2d(0.0,1.0);
      glVertex3fv(b);
    glTexCoord2d(1.0,1.0);
      glVertex3fv(c);
    glTexCoord2d(1.0,0.0);
      glVertex3fv(d);
    glEnd();
    glDisable(GL_TEXTURE_2D);
}

the bricks are in different directions on different sides of the polygon …

Could u show us a snapshot of what you are getting?

Just a side note here, GL_DECAL cannot be used for mini/magnification filtering. It is used with the glTexEnv so I think you should remove these calls.


//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_DECAL);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_DECAL);

ooops! lol attached is my screen shot.

Either your texture coordinates are incorrect for those walls or the vertices are not given in the correct winding order. Recheck your code.

The simplest approach to debug for texture mapping errors is to disable texturing and simply set the texture coordinates as color. If the tex. coords. are fine, you should have a continuous gradient for the whole scene. Identify the walls where there are discontinuities in the texture coordinates and correct them.

For a simpler solution, I think you should see the wrongly ordered polygons and correct their winding.

ok. Thanks a lot.