So, I am struggling with shaders right now in my program. Basically this is the main loop:
heightmap_shader.use();
nanosuit_shader.use();
glm::mat4 nanosuitProj, nanosuitModel, nanosuitView;
nanosuitProj = glm::perspective(glm::radians(45.0f), float(800/600), 0.1f, 1000.0f);
nanosuitView = camera.getViewMatrix();
glUniformMatrix4fv(glGetUniformLocation(nanosuit_shader.getProgramID(), "projection"), 1, GL_FALSE, glm::value_ptr(nanosuitProj));
glUniformMatrix4fv(glGetUniformLocation(nanosuit_shader.getProgramID(), "view"), 1, GL_FALSE, glm::value_ptr(nanosuitView));
// Draw the loaded model
nanosuitModel = glm::translate(nanosuitModel, glm::vec3(0.0f, 2.0f, 0.0f)); // Translate it down a bit so it's at the center of the scene
nanosuitModel = glm::scale(nanosuitModel, glm::vec3(0.05f, 0.05f, 0.05f)); // It's a bit too big for our scene, so scale it down
glUniformMatrix4fv(glGetUniformLocation(nanosuit_shader.getProgramID(), "model"), 1, GL_FALSE, glm::value_ptr(nanosuitModel));
nanosuit_Model.Draw(nanosuit_shader);
glfwSwapBuffers(window);
So basically I use a shader first (heightmap) but do nothing with it. After that I change to the actual necessary shader, and after that I draw the object. This does not work. The screen is empty.
If I comment out
heightmap_shader.use()
the program works fine. Can someone explain this? Am I doing something wrong?
In my head the program should work even with the first shader, since I am switching it everytime. But it seems my program doesn't understand it.
Note: The method use() is:
glUseProgram(shaderId)
where shaderId is the id of the shader after it is compiled.
EDIT:
Just want to say that this SHOULD work, and it was not working because there was a bug in my Shader class.