PDA

View Full Version : colouring triangles



jofoxy
02-27-2005, 11:16 AM
im trying to learn how to light up a triangle strip on a polygon mesh, and i cant seem to get it to work. im using the following...

void faceStrip (CGPolyMesh *m, int faceIndex, int edgeIndex)
{

int i;
CGFaceVertex *f;
RGBAColor *cptr;

// setup vertex array
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, m->V);

glBegin(GL_TRIANGLES);

for (f=m->Fv, i=0 ; i<m->noofFaces ; i++, f++)cptr = m->C + i; // i'th face colour in colour array
glColor3f(cptr->r, cptr->g, cptr->b);

glArrayElement(f->v1);
glColor3f(1.0, 1.0, 0.0);
glArrayElement(f->v2);
glColor3f(1.0, 1.0, 0.0);
glArrayElement(f->v3);
glColor3f(1.0, 1.0, 0.0);





}

glEnd();

glEnableClientState(GL_VERTEX_ARRAY);

does any one know where im going wrong?

thanx

jofoxy

jofoxy
02-27-2005, 11:17 AM
where i say light i mean colour in red for example

knackered
02-27-2005, 11:56 AM
If you've got lighting enabled, glColor does nothing, you must manipulate the colour of the object by changing its material properties.
However, you can still use glColor by using colormaterial:-

glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
glEnable(GL_COLOR_MATERIAL);This will make OpenGL change the ambient and diffuse attributes of the current material whenever you use glColor or equivalent.

jofoxy
02-27-2005, 12:02 PM
i dont mean light up i mean colour in red a triangle stip polygon

Overmind
02-28-2005, 12:55 AM
Why do you call glColor3f(1.0, 1.0, 0.0) between your vertices? You would get only yellow polygons this way, because AFAIK with flat shading the color of the last vertex determines the color of the whole polygon. Or you might get color interpolation between your color and yellow if you activate smooth shading.

dorbie
02-28-2005, 01:14 AM
You need to post your question as an OpenGL question *ONCE* and you should stick to the beginners forum for now.

If you don't get a reply in one thread don't post another two.

Moving thread to beginners forum.