Hi OpenGL community,
Hope you can help me on this.
I have a simple VBO of vertex.
For a reason (it’s 3d modeler software), I can’t have a nice index array to draw my geometry.
What I’ve thinked about was to use display list to do a loop of glDrawElements with, each time, indices it need to draw his polygon:
int facesCount = (int)faces.size();
glNewList(_quadDisplayList, GL_COMPILE);
for(int faceID = 0; faceID < facesCount; ++faceID){ // go throug each face and get an array of indice for this face
const std::vector<int> &face = faces[faceID]; // return "face", an array of 3,4,5+ index.
glDrawElements(GL_POLYGON, face.size(), GL_INT, &face[0]);
}
glEndList();
This doesn’t seems to work… (a simplest display list work well so my display list call is ok, the problem doesn’t came from here).
I’ve searched and find something interesting of the OpenGL doc:
glDrawElements is included in display lists. If glDrawElements is entered into a display list, the necessary array data (determined by the array pointers and enables) is also entered into the display list. Because the array pointers and enables are client-side state, their values affect display lists when the lists are created, not when the lists are executed.
But when I create this display list, no pointer is set because I set all of this after just before the draw…
So (first question), my solution is impossible using this way right?
Maybe I should store all indices (using a loop because indices are by face) in an array, store it in a VBO.
And do a display list using pointer offset:
int facesCount = (int)faces.size();
GLint quadIndices[idxArraySize];
int quadIndiceOffset = 0;
for(int faceID = 0; faceID < facesCount; ++faceID){
const std::vector<int> &face = faces[faceID];
for(unsigned int index = 0; index < face.size(); ++index){
quadIndices[indiceOffset] = face[index]; // the index of the polygon of the face
indiceOffset++;
}
}
// store as VBO
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, _idxBuffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(GLint)*idxArraySize, (GLvoid*)&quadIndices[0], GL_STATIC_DRAW);
int idOffset = 0;
glNewList(_quadDisplayList, GL_COMPILE);
for(int faceID = 0; faceID < facesCount; ++faceID){ // go throug each face and get an array of indice for this face
const std::vector<int> &face = faces[faceID]; // return "face", an array of 3,4,5+ index.
glDrawElements(GL_POLYGON, face.size(), GL_INT, (GLint*)0+idOffset);
idOffset += face.size();
}
glEndList();
But this doesn’t work too…
So (second question), my solution is impossible using this way right?
If any of you have suggestions, this could really help me.
Thanks in advance!
Regards,
Dorian