Hello,
I'm programming a small game with BulletPhysics and OpenGL (2.1).
Yesterday I added lighting to the game, so I needed normals for the objects, too.
But I've got a problem with that:
I'm creating a cuboid with the following code:
Code :m_vVertices.pObj = new CVector3D[8]; GLfloat corners[] = {-vHalfExtents.x, vHalfExtents.y, vHalfExtents.z, vHalfExtents.x, vHalfExtents.y, vHalfExtents.z, vHalfExtents.x, -vHalfExtents.y, vHalfExtents.z, -vHalfExtents.x, -vHalfExtents.y, vHalfExtents.z, -vHalfExtents.x, vHalfExtents.y, -vHalfExtents.z, vHalfExtents.x, vHalfExtents.y, -vHalfExtents.z, vHalfExtents.x, -vHalfExtents.y, -vHalfExtents.z, -vHalfExtents.x, -vHalfExtents.y, -vHalfExtents.z}; for (int i = 0; i < 8; ++i) { m_vVertices.pObj[i].x = corners[i*3]; m_vVertices.pObj[i].y = corners[i*3+1]; m_vVertices.pObj[i].z = corners[i*3+2]; } m_VertexIndices.pObj = new GLuint[6*4]; GLubyte indices[] = {0, 1, 2, 3, 4, 5, 1, 0, 3, 2, 6, 7, 5, 4, 7, 6, 1, 5, 6, 2, 4, 0, 3, 7}; for (int i = 0; i < 24; ++i) { m_VertexIndices.pObj[i] = indices[i]; }
Later, I'm rendering with this code:
Code :glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, 0, static_cast<void*>(m_vVertices.pObj)); glDrawElements(GL_QUADS, 24, GL_UNSIGNED_INT, static_cast<void*>(m_VertexIndices.pObj)); glDisableClientState(GL_VERTEX_ARRAY);
But when I wanted to add normals, I had a problem: As far as I know OpenGL doesn't support surface normals, only vertex normals.
But because I'm reusing shared vertices with the help of an index array, I can't specify normals per vertex beacause - dependent on which face a vertex belongs to - each vertex can have different normals. Is there a way I can still use indices to specify the order of the vertices drawn or do I have to declare shared vertices multiple times (for every face needed)?
Thank you for your answers in advance!



