# Easy way to set face colors with indexed VBOs?

I'm loading OBJs, which lend themselves well to setting up as indexed VBOs, since each vertex is only defined once and then a face definition will reference the same vertex more than once when they share an edge. I want to define face colors based on the materials loaded from the OBJ. This is quite easy in immediate mode, but I've realized that using VBOs will require me to duplicate each vertex in order to have two adjacent faces with different colors. What's the best way to go about solving this without duplicating vertices?

EDIT: Code (LWJGL)

//Get the VBO from the GPU
glBindBuffer(GL_ARRAY_BUFFER, vbo);
//Tell OpenGL what to expect from the VBO
glVertexAttribPointer(0, 3, GL_FLOAT, false, Vertex.SIZE * 4, 0); //Location
glVertexAttribPointer(1, 2, GL_FLOAT, false, Vertex.SIZE * 4, 4 * 3); //Texture Coord
glVertexAttribPointer(2, 3, GL_FLOAT, false, Vertex.SIZE * 4, 4 * 3 + 4 * 2); //Normal

glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glDrawElements(GL_TRIANGLES, size, GL_UNSIGNED_INT, 0);

• You could store the color inside each face and render each in a separate draw call. Then set a uniform in the shader that is the face color for each draw (assuming you are using shaders). – glampert Oct 17 '14 at 4:23
• I am using shaders, but how would I access each face when I'm using glDrawElements() with my GL_ELEMENT_ARRAY_BUFFER and the indices of each vertex? – winduptoy Oct 17 '14 at 4:39
• However, if you really need a single color per face, then it is probably better to duplicate that color in the vertex, as performing one draw call per face is quite inefficient, as you might have imagined. – glampert Oct 17 '14 at 4:49
• It looks like my only option is to duplicate the vertex. – winduptoy Oct 17 '14 at 5:09
• In OpenGL, vertices are only duplicates if every vertex attribute is the same: positions, texture coords, normals, colors, and any other custom attribs in use. You can't index some attributes but not others, or use multiple indices. – bcrist Oct 17 '14 at 9:08