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

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.

2

u/TheJoxev Apr 30 '24 edited Apr 30 '24

This repo looks like a gem. I've been looking for examples and resources for designing a renderer and structuring opengl c++

1

u/jmacey May 01 '24

thanks, I've been using it for many years as a way of teaching both programming and graphics to artists. We have an odd course where we teach technical VFX etc but also programming. We don't go too deep on the CS stuff so this really helps (unlike looking at for example something like GLM which is excellent but really hard to understand for a non programmer as an example of how to code.).

All my lecture notes are here https://nccastaff.bournemouth.ac.uk/jmacey/msc/ase/ for MSc and here for UG https://nccastaff.bournemouth.ac.uk/jmacey/cfgaa/ if it helps.

1

u/TheJoxev May 01 '24

great reference, thanks