Texturing A Pyramid Using A TriFan (Different textures per side)
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:
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.
|
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.
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?
///////////////////////////////////////////////////
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!
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!!!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement