PDA

View Full Version : assign names and colour to premade object



grodslukaren
06-11-2001, 08:22 AM
IŽve got a file from which I load a figure of a head. IŽd like to assign names and colours to each polygon in this head.

I use a operation in my C++ program that reads all the vertexes, normals and textures and put it into a DisplayList that is being called when I want to display the figure. But how do I do to assign names and colours at the same time??

my operation where I load all the data:
unsigned int C3DPaintCanvas::GenerateDisplayList()
{
int i;
int j;
GLint lid=glGenLists(1);
int mcount=0;
int mindex=0;
glNewList(lid, GL_COMPILE);
glBegin(GL_TRIANGLES);
// sizeof(face_indicies) = 151488
// sizeof(face_indicies[0]) = 18
// => for loop 8416 times
for(i=0;i<sizeof(face_indicies)/sizeof(face_indicies[0]);i++)
{
// choose material - enters first time
if(!mcount)
{
SelectMaterial(material_ref[mindex][0]);
mcount=material_ref[mindex][1];
mindex++;
}
mcount--;
// set name ??????
// set colour ???????
////////////////////////////////
//glLoadName (i);
//glPushName (i);
// set the colour
// glColor3f(0.0,1.0,0.0);
//glPopName ();
///////////////////////////////

for(j=0;j<3;j++)
{
int vi=face_indicies[i][j];
// Vertex
int ni=face_indicies[i][j+3];
//Normal index
int ti=face_indicies[i][j+6];
//Texture index
glNormal3f (normals[ni][0],normals[ni][1],normals[ni][2]);
glTexCoord2f(textures[ti][0],textures[ti][1]);
glVertex3f (vertices[vi][0],vertices[vi][1],vertices[vi][2]);
}
}
glEnd();
glEndList();
return lid;
}
// end of GenerateDisplayList()

Korval
06-11-2001, 11:45 PM
OpenGL doesn't have the concept of a triangle having a name, so you're going to have to store that information somewhere yourself.

As to colors, how do you want to select colors? I mean, for a given triangle, how do you want to determine what color it is? Once you figure that out, stick that into the loading code.

grodslukaren
06-12-2001, 05:11 AM
But is it not possible to use naming??
or does the namestack has a limited depth??

I thought for a while that I could store the polygons in a namestack and then use picking to figure out which polygon I want to draw. But if I donŽt understand wrong, picking is
only for figure out which polygon or object is choosed by the mouse. But how can I do if I have coordinates for the object i.e IŽd like to draw polygons I canŽt see from the screen until I rotate my figure... mouse coordinates are not intresting...

/grodslukaren