Jump to content
  • Advertisement
Sign in to follow this  
Murlok

Texturing Haywire

This topic is 3013 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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);                  // generate texture
		glBindTexture(GL_TEXTURE_2D, textureID);
		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, imageWidth, imageHeight, GL_RGB, GL_UNSIGNED_BYTE, tex_image);  
	}
	
		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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!