Mapping 2D texture to multiple GL_TRIANGLES
I'm trying to map a texture to a set of GL_TRIANGLES.
I wrote each triangle creation like this so that the transform and rotation would affect them.
this pretty much creates one quad, made up of GL_TRIANGLES, that would change directions after certain time.
Is it possible for me to map a texture to a set up like this? Or is there a better approach?
I wrote each triangle creation like this so that the transform and rotation would affect them.
this pretty much creates one quad, made up of GL_TRIANGLES, that would change directions after certain time.
Is it possible for me to map a texture to a set up like this? Or is there a better approach?
Code:
for(int hCtr = 0; dimensionH > hCtr; hCtr++){
cW = 0;
float spreadIncrement = spread / dimensionW;
for (int wCtr = 0; dimensionW > wCtr; wCtr++) {
float explodeSpread = time * spreadIncrement;
glTranslatef(explodeSpread, explodeSpread, explodeSpread);
glRotatef(explodeSpread, 1, 1, 1);
glBegin(GL_TRIANGLES);
glTexCoord2f(cW, cH);
glVertex3f(cW, cH, 0);
glTexCoord2f(cW, cH + blockH);
glVertex3f(cW, cH + blockH, 0);
glTexCoord2f(cW + halfBW, cH);
glVertex3f(cW + halfBW, cH, 0);
glEnd();
glTranslatef(explodeSpread, explodeSpread, explodeSpread);
glRotatef(explodeSpread, 1, 1, 1);
cW = cW + halfBW;
glBegin(GL_TRIANGLES);
glTexCoord2f(cW, cH);
glVertex3f(cW, cH, 0);
glTexCoord2f(cW - halfBW, cH + blockH);
glVertex3f(cW - halfBW, cH + blockH, 0);
glTexCoord2f(cW + halfBW, cH + blockH);
glVertex3f(cW + halfBW, cH + blockH, 0);
glEnd();
glTranslatef(explodeSpread, explodeSpread, explodeSpread);
glRotatef(explodeSpread, 1, 1, 1);
cW = cW + halfBW;
glBegin(GL_TRIANGLES);
glTexCoord2f(cW, cH);
glVertex3f(cW, cH, 0);
glTexCoord2f(cW - halfBW, cH);
glVertex3f(cW - halfBW, cH, 0);
glTexCoord2f(cW, cH + blockH);
glVertex3f(cW, cH + blockH, 0);
glEnd();
glTranslatef(-explodeSpread, -explodeSpread, -explodeSpread);
spreadIncrement = spreadIncrement + spreadIncrement;
}
cH = cH + blockH;
}
You've asked a bit of a strange question, and your code isn't clear but I'm pretty sure I understand what you're trying to do, so here's a quick overview.
Think of it like this: Since you're "exploding" a quad into triangle shards, you need to create individual Shard objects. Each Shard has its own 3 vertices and 3 mapping texture coordinates, and then when you're exploding, each shard moves off in its own direction.
When texture mapping a quad, you're using the tex coord {0, 0} for the vertex in one corner, and {1, 1} for the opposite corner's vertex.
Consider your quad dimensions as W x H where W and H are both 1: Your texture coords are the same as your vertex coords. Easy.
When you "smash" the original quad and slice it up into a bunch of triangles, the vertices of the triangles you create are all are between 0 and 1. Since texture coordinates are also from 0 to 1, mapping a texture onto those triangles is easy: the 0-1 vertex values are also the 0-1 texture coordinates.
When you create each shard, set its vertices and texture coordinates, and then your main loop just moves each shard.
Think of it like this: Since you're "exploding" a quad into triangle shards, you need to create individual Shard objects. Each Shard has its own 3 vertices and 3 mapping texture coordinates, and then when you're exploding, each shard moves off in its own direction.
When texture mapping a quad, you're using the tex coord {0, 0} for the vertex in one corner, and {1, 1} for the opposite corner's vertex.
Consider your quad dimensions as W x H where W and H are both 1: Your texture coords are the same as your vertex coords. Easy.
When you "smash" the original quad and slice it up into a bunch of triangles, the vertices of the triangles you create are all are between 0 and 1. Since texture coordinates are also from 0 to 1, mapping a texture onto those triangles is easy: the 0-1 vertex values are also the 0-1 texture coordinates.
When you create each shard, set its vertices and texture coordinates, and then your main loop just moves each shard.
Yes that is exactly what I was going for. I got to to separate along with the texture, thanks!
nice info tnx
nice
nice
I think the accepted answer in the post Mapping a square texture to a triangle nearly covers what im after, if it is indeed possible to index and texture in the way that i am expected to.
Possibly Related Threads...
Thread: | Author | Replies: | Views: | Last Post | |
Texture mapping single 3D object with one draw call | jeonghyunhan | 1 | 4,484 |
Jul 13, 2009 06:05 AM Last Post: ThemsAllTook |
|
Texture Mapping: Loading a texture from a .bmp file? | ishrock | 5 | 10,063 |
Dec 13, 2008 09:27 AM Last Post: ThemsAllTook |
|
OpenGL and cylindrical texture mapping | spsweet | 0 | 6,799 |
May 1, 2007 02:55 PM Last Post: spsweet |
|
problem with basic texture mapping class | wyrmmage | 8 | 7,583 |
Dec 22, 2006 02:25 PM Last Post: wyrmmage |
|
Texture mapping meshes | wyrmmage | 9 | 7,760 |
Nov 30, 2006 08:45 PM Last Post: OneSadCookie |