I encountered a strange problem when rendering different models with OpenGL.
I want to render model A by calling function glDrawArrays and model B with
glDrawElements, but unfortunately, only the model B was rendered with glDrawArrays, and the function glDrawElements was failure to render model. BUT if I comment the code to render model B, the model was correctly rendered by glDrawElements.
Actually, if I draw one model no matter what function I calling, It will draw correctly, But if draw two models with glDrawElements and glDrawArrays simultaneously, only glDrawArrays will draw.
This is my code, please help me.
// **model A**
m_program->bind();
glUniformMatrix4fv(m_program->uniformLocation("model"), 1, GL_FALSE, m_world.data());
m_ebo.bind();
m_vbo.bind();
m_vao.bind();
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 * sizeof(float), nullptr);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 * sizeof(float),
(void*)(3 * sizeof(float)));
glDrawElements(GL_TRIANGLES, 36, GL_UNSIGNED_INT, nullptr);
// **model B**
program->bind();
glUniformMatrix4fv(program->uniformLocation("model"), 1, GL_FALSE, m_world.data());
vbo.bind();
vao.bind();
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), nullptr);
glDrawArrays(GL_LINES, 0, 6);