hi I try to build an index array from a geometry stored in a float* array
my array is :
float *vertex_data;
ind Size_Vertex; // number of floats in array
I think my algorythm to build the indices in good but i didnt manage to display the mesh corectly
void VM2_Mesh::BuildIndices() {
std::vector <unsigned int> ind;
std::vector <Vector3> ReferencedVertices;
Vector3 Cvertex;
bool blisted;
FILE *d = 0x0;
int i,j,index;
d = fopen("debug.txt","w");
for ( i=0;i<Size_Vertex;i+=3) {
// vertex_data is a float* array
blisted = false;
Cvertex = Vector3(vertex_data,vertex_data[i+1],vertex_data[i+2]);
for ( j=0;j<ReferencedVertices.size();j++) {
if (ReferencedVertices[j] == Cvertex){
blisted = true; // already listed
fprintf(d,"already listed @ j = %d (%.2f,%.2f,%.2f) === (%.2f,%.2f,%.2f)\n",
j,ReferencedVertices[j].x,ReferencedVertices[j].y,ReferencedVertices[j].z,
Cvertex.x,Cvertex.y,Cvertex.z
);
break;
}
}
if (!blisted){
ReferencedVertices.push_back(Cvertex);
index = (ReferencedVertices.size() - 1); // we added at the end of the std::vector
ind.push_back( index ); // had this index to our index list
fprintf(d,"ADDING INDICE index = %d (%.2f,%.2f,%.2f)\n",
index,
Cvertex.x,Cvertex.y,Cvertex.z);
}
else {
ind.push_back(j);
fprintf(d,"ADDING INDICE j : %d\n",j);
}
} // end of for ..
Size_Indices = ind.size();
indices = new unsigned int[Size_Indices];
if (!indices)
throw("failed to allocate memory for indices");
for (int n=0;n<ind.size();n++) {
indices[n] = ind[n];
fprintf(d,"i,index no %d : %d\n",n,indices[n] );
}
fclose(d);
}
void VM2_Mesh::Render2() {
glEnableClientState( GL_VERTEX_ARRAY );
glEnableClientState( GL_TEXTURE_COORD_ARRAY );
glEnableClientState(GL_INDEX_ARRAY);
glBindTexture(GL_TEXTURE_2D,texid);
glVertexPointer ( 3, GL_FLOAT, 0, vertex_data );
glTexCoordPointer( 2, GL_FLOAT, 0, text_data );
glIndexPointer(GL_UNSIGNED_INT , 0, indices );
glDrawElements(GL_TRIANGLES, Size_Indices, GL_UNSIGNED_INT,indices);
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
glDisableClientState(GL_INDEX_ARRAY);
}
any idea ?
[Edited by - venomelektro on January 17, 2005 10:10:01 AM]