[RESOLVED] How to texture map a triangle?

Hi,

I have problems about texture mapping a triangle. I am drawing 4 houses with each houses's walls drawn as a cube and its roof drawn as 4 triangles.

Texture mapping the walls is ok. But when I texture map the triangles, strange results appear. When I texture map one triangle with a bitmap image, the texture not only appears on the triangle, it also appears on the 4 walls of all the houses.

The size of the texture is 64x64pix. I used the method used for texture mapping quads. For texture mapping the triangle, I used 3 glTexCoord2f() statements instead of 4.

How do I make sure that the texture is applied on the triangle only and not be applied onto the quads also?
[717 byte] By [ZhiYi] at [2007-11-20 0:05:41]
# 1 Re: [RESOLVED] How to texture map a triangle?
can you post some code??
Andrea_Rossini at 2007-11-10 3:49:08 >
# 2 Re: [RESOLVED] How to texture map a triangle?
This is a code snippet for the texture mapping and vertices for the wall. So far it works fine.

glBindTexture(GL_TEXTURE_2D,texture[2]);
glBegin(GL_QUADS); //Front Right

//Front face
glTexCoord2f(0.0f,0.0f); glVertex3f(2.0f,7.0f,5.0f); //Bottom left
glTexCoord2f(1.0f,0.0f); glVertex3f(6.0f,7.0f,5.0f); //Bottom right
glTexCoord2f(1.0f,1.0f); glVertex3f(6.0f,11.0f,5.0f); //Top right
glTexCoord2f(0.0f,1.0f); glVertex3f(2.0f,11.0f,5.0f); //Top left
......
glEnd();

But when I use texture mapping on the triangular roof, the texture map is applied to the walls as well.

glBindTexture(GL_TEXTURE_2D,texture[3]);
glBegin(GL_POLYGON); //Front right
//Front face
glTexCoord2f(0.0f,0.0f); glVertex3f(2.0f,11.0f,5.0f); //Bottom left
glTexCoord2f(1.0f,0.0f); glVertex3f(6.0f,11.0f,5.0f); //Bottom right
glTexCoord2f(0.5f,1.0f); glVertex3f(4.0f,14.0f,2.5f); //Top
.....
glEnd();

In the Render function, I called the DrawWall() function first, followed by the DrawRoof() function.

I matched the tex coordinates with the vertex coordinates but I don't know why the triangle's texture will override the texture of the wall.
ZhiYi at 2007-11-10 3:50:10 >
# 3 Re: [RESOLVED] How to texture map a triangle?
I'll give a try when at home...
hold on ;)
Andrea_Rossini at 2007-11-10 3:51:08 >
# 4 Re: [RESOLVED] How to texture map a triangle?
The code is OK, can you post the part where you load and initialize the textures ?
JohnyDog at 2007-11-10 3:52:17 >
# 5 Re: [RESOLVED] How to texture map a triangle?
I have 4 textures. Here goes:

GLuint texture[4];

glGenTextures(3,&texture[0]);

//Generate Linear Filtered Texture 0 (Front/back doors)
glBindTexture(GL_TEXTURE_2D,texture[0]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D,0,3,TextureImage[0]->sizeX,TextureImage[0]->sizeY,0,
GL_RGB,GL_UNSIGNED_BYTE,TextureImage[0]->data);

...... //The code for glBindTexture and glTexImage2D functions are repeated for other textures.
ZhiYi at 2007-11-10 3:53:16 >
# 6 Re: [RESOLVED] How to texture map a triangle?
glGenTextures(3,&texture[0]);

generates only 3 textures names, not 4.

and I see in the previous post that:

glBindTexture(GL_TEXTURE_2D,texture[3]);

is it your intention? you are using the 4th texture from a list where you generated only 3 names...
Andrea_Rossini at 2007-11-10 3:54:17 >
# 7 Re: [RESOLVED] How to texture map a triangle?
oooh....i've got it. Yes, it was a mistake. I forgot to change it from 3 to 4 textures. :D
ZhiYi at 2007-11-10 3:55:21 >