# How to use OpenGL's glUseProgram?

While in the rendering loop, is it OK to call glUseProgram? Does it have a big overhead? I'm planing to use a program for each different material in the scene. I'm a real beginner with OpenGL and I'm afraid that changing the program several times for each frame it's not the best practice (although I can't think of something else).

It's more clear if you do it the way you described. For me, clarity always wins over performance. It will be easier to trace bugs if you enclose only the code that absolutely needs the shaders with glUseProgram(...).