I have two shaders created using the code provided by theCherno in his OpenGL tutorial, and I'm trying to render two different "models".
The project is pretty big, so I'll do my best to include relevant pieces of code.
this is the Model::Draw()
function:
void Model::Draw(Shader shader, Camera camera)
{
//Setting uniforms
shader.SetUniformMat4("view", camera.GetViewMatrix());
shader.SetUniformMat4("projection", camera.GetProjectionMatrix());
shader.SetUniformMat4("model", m_Transform);
m_Mesh.Draw(shader);
}
m_Mesh.Draw(shader)
calls Mesh::Draw(Shader shader)
:
void Mesh::Draw(Shader shader) {
shader.Bind();
GlCall(glBindVertexArray(VAO));
GlCall(glDrawElements(GL_TRIANGLES, (GLsizei) Indices.size(), GL_UNSIGNED_INT, 0));
//GlCall(glBindVertexArray(0));
//glActiveTexture(GL_TEXTURE0);
}
This is the main rendering loop:
while (!glfwWindowShouldClose(window))
{
simple.SetUniform3f("objColor", 1.0f, 1.0f, 1.0f);
lightModel.Draw(simple, context.ActiveCamera);
//Render
shaded.SetUniform3f("objectColor", glm::vec3(1.0f));
shaded.SetUniform3f("lightColor", glm::vec3(1.0f));
shaded.SetUniform3f("lightPos", glm::vec3(1.0f));
model.Draw(shaded, context.ActiveCamera);
//OPENGL
glfwSwapBuffers(window);
glfwPollEvents();
}
By using the glGetError() function I got that the error is 1281 on Shader.Bind(), which is just a single line of code:
glUseProgram(m_RenderId);
It also prints that the three uniforms model
, view
and perspective
in the shader do not exist (this is a check that my shader class does and it issues it when glGetUniformLocation(m_RenderId, uniformName)
returns -1
), even if they are present.
Also by debugging, I found out that both shaders have two different m_RenderId, so I think there's no problem there. The error occurs the second time the while loop runs. So I might be forgetting to do something at the end of the draw call but by looking online I couldn't find anything.
And what is strange is that it gives me an error only if I try to render two different meshes with two different shaders, If I try to render both the model
mesh and the lightModel
with the same shader it works fine.
I am pretty new to OpenGL and I've done my best to actually understand what the code is doing but this error just doesn't make sense to me, so I excuse in advance if this is a silly mistake. I might be also missing some code pieces in the question if, more is necessary I'll add it.
How can I fix it?