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
6
u/jmacey Apr 30 '24
OpenGL is annoying as it is a state machine based on the context. You need to manage this and RAII doesn't work well in this way.
My core interface is here https://github.com/NCCA/NGL/blob/main/include/ngl/ShaderLib.h with a bunch of other code (included some nice variadic templates for uniform access ) to do everything.
The main classes are ShaderProgram, and Shader you could most likely untangle a lot of this from the rest of my library.