View Full Version : Help drawing with TRIANGLE_STRIP

fcoutel

09-10-2002, 04:42 AM

Hi!

I have defined a plane with a specific mesh. I have created the following arrays:

xmesh[i][j];

ymesh[i][j];

zmesh[i][j] where i=0,dim1-1 j=0,dim2-1

colors are in ColorP[k][i][j]; where k=0,2 (red, green, blue)

normals are in Normal[l][i][j] where l=0,2

Now I would like to display those points with associated colors and normals using TRIANGLE_STRIP, can someone help me do this?

Thanks,

nexusone

09-10-2002, 09:03 AM

One change would be you in your variables:

xmesh[number_of_points][3] = {{x,y,z}};

ymesh[number_of_points][3] = {{x,y,z}};

zmesh[number_of_points][3] = {{x,y,z}};

normal[number_of_triangles] = {{x,y,z}};

color[number_of_points][3] = {{r,g,b},....,{r,g,b}};

// there maybe some error's I did this off the top of my head... but should give you an idea.

glBegin(GL_TRIANGLE_STRIP);

for(i=0;i <= number_of_points;i++) // number of points to process

{

glColor4fv( color[i] );

glNormal3fv( normal[i] );// maybe add another loop to process normal on a per triangle basis.

glVertex3f(xmesh[i], ymesh[i], zmesh[i] );

}

glEnd();

Hope this helps

Originally posted by fcoutel:

Hi!

I have defined a plane with a specific mesh. I have created the following arrays:

xmesh[i][j];

ymesh[i][j];

zmesh[i][j] where i=0,dim1-1 j=0,dim2-1

colors are in ColorP[k][i][j]; where k=0,2 (red, green, blue)

normals are in Normal[l][i][j] where l=0,2

Now I would like to display those points with associated colors and normals using TRIANGLE_STRIP, can someone help me do this?

Thanks,

[This message has been edited by nexusone (edited 09-10-2002).]

vincoof

09-11-2002, 01:16 AM

nexusone : that may not work because I think the mesh isa rectangular patch.

fcoutel : is that right that your mesh[i][j] is organized so that [i] represents rows and [j] represents columns ? If it is the case, then your mesh is is a rectangular patch and it's very easy to render it with triangle strips.

fcoutel

09-11-2002, 02:18 AM

Hi there!

Thanks guys for your response, yes it is correct that mesh[i][j] is organized so that [i] represents rows and [j] represents columns

so how can I display the mesh?

vincoof

09-11-2002, 05:47 AM

for each i from 0 to dim1-2 // not dim1-1

glBegin(GL_TRIANGLE_STRIP);

for each j from 0 to dim2-1

glNormal3f(Normal[0][i][j], Normal[1][i][j], Normal[2][i][j]);

glColor3ub(Color[0][i][j], Color[1][i][j], Color[2][i][j]);

glVertex3f(xmesh[i][j], ymesh[i][j], zmesh[i][j]);

glNormal3f(Normal[0][i+1][j], Normal[1][i+1][j], Normal[2][i+1][j]);

glColor3ub(Color[0][i+1][j], Color[1][i+1][j], Color[2][i+1][j]);

glVertex3f(xmesh[i+1][j], ymesh[i+1][j], zmesh[i+1][j]);

end for

glEnd();

end for

note: I've used "glVertex3f" and "glNormal3f" because I assume your vertex and normal data type is GL_FLOAT, and "glColor3ub" because I assume your color data type is GL_UNSIGNED_BYTE. But if your data types are different, of course you must call something else than glVertex3f, glNormal3f and glColor3ub

ps: as a matter of optimization, I recommend you to organize your data differently so that you can use vertex arrays.

[This message has been edited by vincoof (edited 09-11-2002).]

[This message has been edited by vincoof (edited 09-11-2002).]

Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.