Hey guys,
I’m currently trying to draw 2 different meshes with help of vertex array objects.
Drawing one mesh multiple times is no problem. But two of them together in one scene does not work.
At first I thought that I overwrite one of the vaos with false information, but thats not the case.
If I try to render 2 meshes only the last draw call has an effect on the visuals of the scene.
Means: Last mesh initialized will be rendered.
You don’t show any calls to glVertexAttribPointer() or glEnableVertexAttribArray(). Those should probably go in the mesh constructor, after the VAO is bound.
Note that what is actually stored in a VAO is the state modified by those calls, which includes the VBO which was bound to GL_ARRAY_BUFFER at the time of the glVertexAttribPointer() call, but doesn’t include the current GL_ARRAY_BUFFER binding (so as it stands, the vbo_.bind() call in the mesh constructor is pointless).
[QUOTE=GClements;1280084]You don’t show any calls to glVertexAttribPointer() or glEnableVertexAttribArray(). Those should probably go in the mesh constructor, after the VAO is bound.
Note that what is actually stored in a VAO is the state modified by those calls, which includes the VBO which was bound to GL_ARRAY_BUFFER at the time of the glVertexAttribPointer() call, but doesn’t include the current GL_ARRAY_BUFFER binding (so as it stands, the vbo_.bind() call in the mesh constructor is pointless).[/QUOTE]
I didn’t thought this is relevant because I can draw a mesh by itself.
But here’s the code where I link my vertex shader in variables.
This is form my shader_program.cpp
void shader_program::link_attribute(const GLchar *attribName, int size, int stride, int offset){
GLint attrib = glGetAttribLocation(program, attribName);
glVertexAttribPointer(attrib, size, GL_FLOAT, GL_FALSE, sizeof(GLfloat)*stride, (void*)(sizeof(GLfloat)*offset));
glEnableVertexAttribArray(attrib);
}
These will be set after every mesh constructing.
Mesh Constructing
Program linking and using
linking variables to shader (Code above)
setting uniforms
And which VBO and VAO are bound when you call that?
If that’s called after the mesh constructor, when the mesh’s VAO and VBO are bound, it should be fine.
OTOH, if you construct all of the meshes first, then link the attributes afterwards, all of the settings will be stored in the VAO for the last mesh which was constructed, as that’s the one which will be bound at the time.