Sign in to follow this  
Murlok

Texturing Haywire

Recommended Posts

Murlok    100
Hello to all. I'm currently facing a problem. I've currently set a texture however i'm not sure why the texture seems to be distorted. I've attached a photo of the texture and my code for initialising the texture and applying it is as such initialising of the texture
	tex_image[0] = LoadBMPFile("woodenfloor.bmp");
	tex_image[1] = LoadBMPFile("wall.bmp");
	tex_image[2] = LoadBMPFile("check.bmp");

	for (int i = 0;i < 3; i++)
	{
		glGenTextures(1,  &textureID[i]);                  // generate texture
		glBindTexture(GL_TEXTURE_2D, textureID[i]);
		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, imageWidth, imageHeight, GL_RGB, GL_UNSIGNED_BYTE, tex_image[i]);  
	}
	
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
		glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glEnable(GL_TEXTURE_2D);	// enable 2D texturing  


The code for applying it to the texture
	glBindTexture(GL_TEXTURE_2D, textureID[2]);
	glMaterialfv(GL_FRONT, GL_AMBIENT, gAmbientfloor);
	glMaterialfv(GL_FRONT, GL_AMBIENT, gDiffusefloor);
	glBegin(GL_QUADS);
	glNormal3f(0.0f, 0.0f, 1.0f);
	glVertex3f(-100.0f, 0.0f, 80.0f);glTexCoord2f(0.0f, 0.0f);	
	glVertex3f(100.0f, 0.0f, 80.0f);glTexCoord2f(1.0f, 0.0f);
	glVertex3f(100.0f, 100.0f, 80.0f);glTexCoord2f(1.0f, 1.0f);
	glVertex3f(-100.0f, 100.0f, 80.0f);glTexCoord2f(0.0f, 1.0f);
	glEnd();


Share this post


Link to post
Share on other sites
Danny02    279
The problem is caused by the texture coords. You have to define them before defining the vertex position, so how you wrote it you'r defining the tex coords everytime for the next vertex

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this