Sign in to follow this  
run_g

Problems with Textures

Recommended Posts

Hello, I am trying to texture map 2 images to seperate sets of polygons (triangles) using the code below. But instead of having a continous smooth output on the triangles, there are gaps and unexplained patterns on the output, eventhough there are no gaps in the triangle-mesh and no patterns on either of the original texture-images used to map the triangles. please does anyone know how I can fix this problem? X Thanks unfortuantely I can't insert links to the images yet, but i hope u understand the question.
void SimplePolyMesh::TexMapDraw(  int textureID,  point3D *triangleVerts  ){

	GLuint  atexture[1];
	color.ambient_diffuse_specular( .9,  .9,  .9, .9,  .9,  .9,     .9,   .9,  .9  );

	if( textureID == 0 )
		atexture[0] = *Display::tryObj.hTexture;         
	if( textureID == 1 )
		atexture[0] = *Display::tryObj.nTexture;         


	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);		  
	glEnable(GL_BLEND);		                                  
	glBindTexture(GL_TEXTURE_2D, atexture[0]);
	glEnable(GL_TEXTURE_2D);
//===================================================


	triangleNormal  =  ( triangleVerts[1] - triangleVerts[0] ).normalised_cross_prod( triangleVerts[2] - triangleVerts[0] );


	glBegin( GL_TRIANGLES );
	for( int j=0; j < 3; j++ ){

		if (j==0) glTexCoord2f(  1,  1   );// supply texture coordinates
		if (j==2) glTexCoord2f(  0,  0   );
		if (j==3) glTexCoord2f(  0,  1   );  

		glVertex3f( triangleVerts[j].getX(), triangleVerts[j].getY(), triangleVerts[j].getZ() );
		glNormal3f( triangleNormal.getX(), triangleNormal.getY(), triangleNormal.getZ() );
	}
		
	glEnd( );
	glFlush( );  

	glDisable(GL_BLEND);
	glDisable(GL_TEXTURE_2D);
}



[Edited by - run_g on January 29, 2008 8:46:14 AM]

Share this post


Link to post
Share on other sites
Just render 1 triangle


glBegin(GL_TRIANGLES);
glTexCoord2f(0.0, 0.0);
glVertex3f(0.0, 0.0, 0.0);
glTexCoord2f(1.0, 0.0);
glVertex3f(1.0, 0.0, 0.0);
glTexCoord2f(0.0, 1.0);
glVertex3f(0.0, 1.0, 0.0);
glEnd();



and if it looks ok, ...

Share this post


Link to post
Share on other sites

if (j==0) glTexCoord2f( 1, 1 );// supply texture coordinates
if (j==2) glTexCoord2f( 0, 0 );
if (j==3) glTexCoord2f( 0, 1 );


Why are you checking if j == 3? it can't be 3, because you're increasing it only when it's less than 3! (so just numers 1, 2 and 0) - It'd look like this:


if (j==0) glTexCoord2f( 1, 1 );// supply texture coordinates
if (j==1) glTexCoord2f( 0, 0 );
if (j==2) glTexCoord2f( 0, 1 );

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