I'm trying to make my opengl model manager with assimp.
Here's the calls which I use to create my vertex "buffer"
GLuint IGraphicsManager::CreateVertexBuffer( void *srcData ,unsigned int size)
{
GLuint buffer;
glGenBuffers(1,&buffer);
glBindBuffer(GL_ARRAY_BUFFER,buffer);
glBufferData(GL_ARRAY_BUFFER,size,srcData,GL_STATIC_DRAW);
return buffer;
}
GLuint IGraphicsManager::CreateIndexBuffer( void *srcData,unsigned int size )
{
GLuint buffer;
glGenBuffers(1,&buffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,buffer);
glBufferData(GL_ELEMENT_ARRAY_BUFFER,size,srcData,GL_STATIC_DRAW);
return buffer;
}
Here's how I use them
std::vector<StaticVertex> m_verts;
std::vector<unsigned int> m_indices;
if (!pModel->LoadMesh("sphere.3ds",m_verts,m_indices))exit(1);
m_modelBuf = pGraphics->CreateVertexBuffer(&m_verts[0],sizeof(StaticVertex)*m_verts.size());
m_indexBuf = pGraphics->CreateIndexBuffer(&m_indices[0],sizeof(unsigned int)*numIndices);
numIndices = m_indices.size();
std::vector<StaticVertex> m_roomVerts;
std::vector<unsigned int> m_roomIndices;
if(!pModel->LoadMesh("room.3ds",m_roomVerts,m_roomIndices))exit(1);
m_roomBuf = pGraphics->CreateVertexBuffer(&m_roomVerts[0],sizeof(StaticVertex)*m_roomVerts.size());
m_indexBuf = pGraphics->CreateIndexBuffer(&m_roomIndices[0],sizeof(unsigned int)*numRoomIndices);
the LoadMesh is something that I have already tested and it's working well
I use the following code to draw them
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER,m_roomBuf);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_roomIndex);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(StaticVertex),0);
glDrawElements(GL_TRIANGLES,numRoomIndices,GL_UNSIGNED_INT,(void*)0);
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER,m_modelBuf);
glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,sizeof(StaticVertex),0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,m_indexBuf);
glDrawElements(GL_TRIANGLES,numIndices,GL_UNSIGNED_INT,0);
Then when I come to the second glDrawElements call, the app crashed with error 0xc000005
What's that matter with them? I just can't find any memory access violation stuff to prove this exit code.
By the way, the vertex array object is something that really confuses me. Any tutorial that simply aims to draw multiple objects?