unsigned int VertexBuffer::WriteIndices( const VertexArray & va, const unsigned int icount, const unsigned int vcount, std::vector<unsigned int> & index_buffer) { const unsigned int * faces = 0; int fn; va.GetFaces(faces, fn); assert(icount + fn <= index_buffer.size()); unsigned int * ib = &index_buffer[icount]; for (int j = 0; j < fn; ++j) { ib[j] = faces[j] + vcount; } return icount + fn; }
void RenderInputScene::DrawVertexArray(const VertexArray & va, float linesize) const { const float * verts; int vertcount; va.GetVertices(verts, vertcount); if (verts) { glVertexPointer(3, GL_FLOAT, 0, verts); glEnableClientState(GL_VERTEX_ARRAY); const unsigned char * cols; int colcount; va.GetColors(cols, colcount); if (cols) { glColorPointer(4, GL_UNSIGNED_BYTE, 0, cols); glEnableClientState(GL_COLOR_ARRAY); } const int * faces; int facecount; va.GetFaces(faces, facecount); if (faces) { const float * norms; int normcount; va.GetNormals(norms, normcount); if (norms) { glNormalPointer(GL_FLOAT, 0, norms); glEnableClientState(GL_NORMAL_ARRAY); } const float * tc = 0; int tccount; if (va.GetTexCoordSets() > 0) { va.GetTexCoords(0, tc, tccount); if (tc) { glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, tc); } } glDrawElements(GL_TRIANGLES, facecount, GL_UNSIGNED_INT, faces); if (tc) glDisableClientState(GL_TEXTURE_COORD_ARRAY); if (norms) glDisableClientState(GL_NORMAL_ARRAY); } else if (linesize > 0) { glLineWidth(linesize); glDrawArrays(GL_LINES, 0, vertcount / 3); } if (cols) glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); } }