Search code examples
c++opengl3dlightingshading

OpenGL per object materials


I am writing my first 3D program in OpenGL 3.3 and I'm finding problems setting different materials for different objects. I managed to draw 3 spheres (vertices are stored in one VAO and then translated and drawn) and using uniforms I changed their appearance from the vertex shader. Now the problem is that the spheres should have different materials but I cannot figure out how to set different uniforms for each sphere. What is the best way to do that?


Solution

  • gl_VertexID can be used . But best in this case is standandalone vbo I think.

    https://rocketgit.com/user/bowler17/gl/source/tree/branch/wrench/blob/t.c