I’m just beginning to learn OpenGL. With all of the tutorials I’ve seen, they demonstrate using a fragment shader to set the color of all the objects in view. What I haven’t found yet is how you would use a fragment shader on just one of the objects, giving different objects different colors. How do you do that?
To provide background to the question, I’m drawing a simple scene with a house and a road in 2d. I have discovered how to set the colors of each of my objects (the main body of the house, the window, etc) using the fixed graphics pipeline, I just don’t understand how to set the colors using fragment shaders.
Any clarification would be greatly appreciated, including correction if I’m misunderstanding something.
As RobertRouhani said, make the color a uniform and change it for each object.
You can simply change the shader program with
glUseProgramand rendering calls after it will use the different shader.See this: https://gamedev.stackexchange.com/questions/22216/using-multiple-shaders