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);
}