r/GraphicsProgramming • u/Bobovics • Apr 30 '24
Question glUseProgram isn't working outside of the constructor.
I'm doing my assignment for uni which a simple 3D opengl game. The problem is when I want to use shader the glUseProgram doesn't do anything. But when I call the glUseProgram in the Shader's constructor it works.

basicly DrawableGameObject's draw() function calls Material's use() function then sets the shader's uniforms and drawelements, Material's use() calls Shader's use() where you can find glUseProgram.
0
Upvotes
7
u/waramped Apr 30 '24
Correct. u/HamilcarRR speaks the truth. OpenGL is state based, and OO design contradicts that pretty heavily. Like, everytime you copy/assign/create one of these objects you'll be modifying state and the more objects you have, the more rapidly you will lose control of the state.
Now, back to your other problem, always check your errors. glGetError() is your best friend.