|
-
Jul 31st, 2006, 05:12 AM
#1
Thread Starter
Lively Member
[RESOLVED] How to texture map a triangle using OpenGL?
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?
-
Jul 31st, 2006, 10:00 AM
#2
Thread Starter
Lively Member
Re: How to texture map a triangle using OpenGL?
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();
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|