Advertisement

Texturing A Pyramid Using A TriFan (Different textures per side)

Started by September 30, 2001 09:40 PM
3 comments, last by orbis 23 years, 4 months ago
Hey guys! I need to be pointed in the right direction here. How do I texture a pyramid created using GL_TRIANGLE_FAN. I want a different texture on each side of the pyramid. Is this possible? I tried texturing (incorrectly obviously) my pyramid using the code below: /////////////////////////////////////////////////// glBegin(GL_TRIANGLE_FAN); glColor3f(1.0f,0.0f,0.0f); glTexCoord2f(0.5f,1.0f); glVertex3f(0.0f,1.0f,0.0f); glColor3f(0.0f,0.0f,1.0f); glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,-1.0f,1.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(1.0f,-1.0f,1.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(1.0f,-1.0f,-1.0f); glTexCoord2f(1.0f,0.0f); glVertex3f(-1.0f,-1.0f,-1.0f); glTexCoord2f(1.0f,1.0f); glVertex3f(-1.0f,-1.0f,1.0f); glEnd(); ////////////////////////////////////////////////// What I end up with is a pyramid with my texture nicely sitting on one face and the rest of the faces have a portion of the texture smeared accross them. I am sure this is a simple problem. Any help and /or flames are greatly appreciated. -The Headstones are talking... Can you hear them?
-The Headstones are talking... Can you hear them?
It depends on how your texture is drawn, but try something like this:

      glBegin( GL_TRIANGLE_FAN );      glTexCoord3f( 0.50f, 1.0f ); glVertex3f( 0.0f, 1.0f, 0.0f );      glTexCoord2f( 0.00f, 0.0f ); glVertex3f(-1.0f,-1.0f, 1.0f );      glTexCoord2f( 0.25f, 0.0f ); glVertex3f( 1.0f,-1.0f, 1.0f );      glTexCoord2f( 0.50f, 0.0f ); glVertex3f( 1.0f,-1.0f,-1.0f );      glTexCoord2f( 0.75f, 0.0f ); glVertex3f(-1.0f,-1.0f,-1.0f );      glTexCoord2f( 1.00f, 0.0f ); glVertex3f(-1.0f,-1.0f, 1.0f );    glEnd();  


That''s assuming your texture looks like a triangle, which is what I assume from what you''ve tried so far.


codeka.com - Just click it.
Advertisement
Thanks... What I really wanted to do though is (your code does what it is supposed to do perfectly) have a different texture per each side of the pyramid. I think what I have to do is combine all four textures into one big texture aranged vertically. Any thoughts anyone? Here is my current code:

///////////////////////////////////////////////////
glBindTexture(GL_TEXTURE_2D, tList[TriTex]);
glBegin(GL_TRIANGLE_FAN);
glColor3f(1.0f,0.0f,0.0f);
glTexCoord2f(0.5f,1.0f); glVertex3f(0.0f,0.0f,0.0f); // Top
glColor3f(0.0f,0.0f,1.0f);
glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,(-1.0f-yElongf),1.0f); // Front Left-Bottom
glTexCoord2f(1.0f,0.0f); glVertex3f(1.0f,(-1.0f-yElongf),1.0f); // Front Right-Bottom
glTexCoord2f(0.0f,0.0f); glVertex3f(1.0f,(-1.0f-yElongf),-1.0f);
glTexCoord2f(1.0f,0.0f); glVertex3f(-1.0f,(-1.0f-yElongf),-1.0f);
glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,(-1.0f-yElongf),1.0f);
glEnd();

glBindTexture(GL_TEXTURE_2D, tList[LogoTag]);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,1.0f); glVertex3f(1.0f,(-1.0f-yElongf),1.0f); // BAck-Right
glTexCoord2f(0.0f,0.0f); glVertex3f(-1.0f,(-1.0f-yElongf),1.0f); // top-Right
glTexCoord2f(1.0f,0.0f); glVertex3f(-1.0f,(-1.0f-yElongf),-1.0f); // Top-Left
glTexCoord2f(1.0f,1.0f); glVertex3f(1.0f,(-1.0f-yElongf),-1.0f); // Back-Left

glEnd();
//////////////////////////////////////////////////

-The Headstones are talking... Can you hear them?
-The Headstones are talking... Can you hear them?
As far as I understand the problem, you shouldn''t arrange the images for each side ''stacked'' on each other in one texture, you should rather arrange them in a way so that every image shares two edges. I think I expressed myself rather bad, but I think you could guess what I mean if I say, you only have one single texCoord for the tip.

Well, try aranging them in a ''circle'' (of course not a round one!)
Maybe it helps...



Yesterday we still stood at the verge of the abyss,
today we''re a step onward!
Yesterday we still stood at the verge of the abyss,today we're a step onward! Don't klick me!!!
Thanks! I will give it a try.

-The Headstones are talking... Can you hear them?
-The Headstones are talking... Can you hear them?

This topic is closed to new replies.

Advertisement