I am having trouble getting Eigen::Vector3f and Opengl ES 2.0 VBO to work together. My initial attempt was glVertexAttribPointer(VERTEX, 3, GL_FLOAT , sizeof(Vertex), 0 ). While this draws nothing if I start to play with the stride values I can see a broken mesh. This is my current code which leads to crash. In my old code I was using simple vector3 class made from 3 floats which was working fine.
struct Vertex {
Eigen::Vector3f pos ;
Eigen::Vector3f normal;
};
std::vector<Vertex> Vertices;
std::vector<ushort16> Indices;
...
GLuint vao;
uint32 vboID, vboID2;
glGenVertexArraysOES(1, &vao);
glBindVertexArrayOES(vao);
glGenBuffers(1, &vboID);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glBufferData(GL_ARRAY_BUFFER, GL_STATIC_DRAW , sizeof(Vertex) * Vertices.size(), &Vertices[0]);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glGenBuffers(1, &vboID2);
glBindBuffer(GL_ARRAY_BUFFER, vboID2);
glBufferData(GL_ARRAY_BUFFER, GL_STATIC_DRAW , sizeof(ushort16) * m_vIndices.size(), &Indices[0]);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ARRAY_BUFFER, vboID);
glEnableVertexAttribArray(VERTEX);
glVertexAttribPointer(VERTEX, 3, GL_FLOAT , sizeof(Vertex), &Vertices[0].pos );
glEnableVertexAttribArray(NORMAL);
glVertexAttribPointer(NORMAL, 3, GL_FLOAT , sizeof(Vertex), &Vertices[0].normal );
glBindBuffer(GL_ARRAY_BUFFER, vboID2);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArrayOES(0);
...
glBindBuffercall, and you are presumably uploading your indices to the wrong buffer object target (assuming you have the index buffer bound toGL_ELEMENT_ARRAY_BUFFERand notGL_ARRAY_BUFFER). You are free to upload data to a buffer object by binding it anywhere you want, but later on when you callglVertexAttribPointer (...)that requires it to be bound toGL_ARRAY_BUFFERandglDrawElements (...)requires it to be bound toGL_ELEMENT_ARRAY_BUFFER. - Andon M. Coleman