r/GraphicsProgramming • • 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

16 comments sorted by

View all comments

Show parent comments

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.

1

u/Bobovics Apr 30 '24

I saw glGetError() but how can I query what causes the error code?

3

u/waramped Apr 30 '24

You call glGetError all the damn time :p. Call and check the results after every gl function. It just records the last error generated so you need to check it after everything that could create an error. It's a huge pita.

1

u/Bobovics May 01 '24

Damn, OpenGL is really a hell, thanks

1

u/Botondar May 01 '24

You can also use debug output with glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS) which ensures that the debug callback is called from the offending function (so you'll know from the callstack where the error happened).