Ive got a square texture created from an NSImage, what I would like to do is draw a tetrahedon(sp?) with four sides, and on each side draw this texture fully within the triangle, as a square entirely within each triangular face.
So Ive gotten the tetrahedron drawn without any problems, but I seem to be getting lost drawing the square texture within it.
…the best Ive managed is to draw a corner of the image inside the triangle…
has anyone seen this done or got any suggestions?
here is my latest (unsuccessful) effort
glBegin( GL_TRIANGLES ); // Draw a triangle
glVertex3f( 1.0f, 1.0f, 1.0f );
glVertex3f( 1.0f, -1.0f, -1.0f );
glVertex3f( -1.0f, 1.0f, -1.0f );
glEnd();
First of all, let me tell you that you’re using the glTexCoord* functions in a wrong way. When you use textures, you have to map a tex coord to every specified vertex like this:
If my calculations are correct, the square that fits inside a triangle which has a side of 1 should have a side of: sqrt(3) / (2 + sqrt(3)) = 0.464
So if the vertices of the triangle are at (0,0), (1,0) and (0.5, 0.866) then the vertices of the square are at (0.270, 0), (0.732, 0), (0.732, 0.464) and (0.270, 0.464).
create a GL_POLYGON with 7 vertexes.
3 vertexes of the triangle
and betweend those 4 vertexes (wherever you want)
and on those u use glTexCoord2f.
make sure the 4 vertexes of the quad are on the same line between the other 3 vertexes, so it looks like a triangle.