This sounds weird but it really seems like for some reason the vaoID i use does not work.
Ive just implemented a new entity system ( as already discribed here)
Instead of passing the Mesh-class object containing the vaoID, indexNumber and vertexNumber to my loadMesh() and render() functions i store all mesh objects inside of a
std::multimap<unsigned int, Component*>
and using the entity IDs i can access every entities components through this multimap.
here is how i load my vertices and indices into my vao
glCreateVertexArrays(1, &vaoID);
glGenBuffers(1, &vboID);
glGenBuffers(1, &iboID);
//associate vertexArray with vboID and indexArray with iboID
glNamedBufferStorage(vboID, sizeof(Vertex)*vertexNum, &vertexArray[0], GL_STATIC_DRAW);
glNamedBufferStorage(iboID, sizeof(unsigned int)*indexNum, &indexArray[0], GL_STATIC_DRAW);
glVertexArrayElementBuffer(vaoID, iboID);
//vaoID vertex attrib array binding location 0 -> vboID
glVertexArrayVertexBuffer(vaoID, 0, vboID, 0, sizeof(Vertex));
//vao binding location 0 -> attribute 0
glVertexArrayAttribBinding(vaoID, 0, 0);
glVertexArrayAttribFormat(vaoID, 0, 4, GL_FLOAT, GL_FALSE, offsetof(Vertex, position));
glVertexArrayAttribBinding(vaoID, 1, 0);
glVertexArrayAttribFormat(vaoID, 1, 4, GL_FLOAT, GL_FALSE, offsetof(Vertex, color));
//here i initialize the current component with the relevant data
componentItr->second->setVAO(vaoID);
componentItr->second->setVertexNum(vertexNum);
componentItr->second->setIndexNum(indexNum);
when i render, i do it like this
void Graphic::render()
{
for (unsigned int c = 0; c < Component::entityComponents.size(); ++c) {
std::multimap<unsigned int, Component*>::iterator cItr = Component::entityComponents.find(c);
std::multimap<unsigned int, Component*>::iterator lastC = Component::entityComponents.upper_bound(c);
if(cItr != Component::entityComponents.end()){
for (; cItr != lastC; ++cItr) {
if (cItr->second->getComType() == ComType::Space) {
glm::vec3 position = cItr->second->getPos();
glm::mat4 translate = glm::translate(Camera::camMatrix(), position);
glm::mat4 rotate = glm::rotate(translate, 2.0f, glm::vec3(1.0f, 1.0f, 1.0f));
glm::mat4 fullMatrix = glm::scale(rotate, glm::vec3(1.0f, 1.0f, 1.0f));
currentShader.addUniform("transformationMatrix", fullMatrix);
//printf("%f %f %f
", Camera::position.x, Camera::position.y, Camera::position.z);
}
if (cItr->second->getComType() == ComType::Mesh) {
GLuint vaoID = cItr->second->getVAO();
unsigned int indexNum = cItr->second->getIndexNum();
glBindVertexArray(vaoID);
glEnableVertexArrayAttrib(vaoID, 0);
glEnableVertexArrayAttrib(vaoID, 1);
glDrawElements(GL_TRIANGLES, indexNum, GL_UNSIGNED_INT, nullptr);
glBindVertexArray(0);
}
}
}
}
}
i checked using breakpoints, the vao stays the same. and i did not change any of the loading or rendering process. i just changed how i access the ids in my entity objects.
Is there anything else openGL needs for rendering exept an integer ID and an integer of index Count?
thanks