DIfferent Objects with different shaders in one scene

In my renderScene subroutine I call for a stream of particles drawn with a shader attached (for updating color and position of the particles). Now I just want to draw another object in the scene, i.e. a teapot, but this object get affected by the shader for the particles…is there a way to disable the shader when drawing the teapot, or to assign the particle shader only to the particles?

glUseProgramObject(shaderHandle);
…draw particles…
glUseProgramObject(0);
…draw teapot…

Thanks it works!

Can you extend your awnser by telling me how I can use a secondary shader for the teapot?

and next, enabling and disabling the shaderprogram decreases the framerate to 50%, is there another option?

Originally posted by Dylan:
Can you extend your awnser by telling me how I can use a secondary shader for the teapot?

glUseProgramObject(shaderHandle);
…draw particles…
glUseProgramObject(shaderHandle2);
…draw teapot…

enabling and disabling the shaderprogram decreases the framerate to 50%, is there another option?

Switching shaders is always a bit slow. If you had 1000 FPS and now you have 500 FPS, then I think it’s ok, but if you had 100 FPS and now you have 50 FPS, then you must be doing something wrong since you use only one shader and you enable/disable it only once per frame.
Note thet you do not need to call functions such as glUniformLocation every frame.

before all you must be sure that your shaders have been compiled correctly ready to use.

then in your draw function,

glUseProgram(handle1)
//draw something stuff

glUseProgram(handle2)
//draw something stuff

Or you write a super shader which include the multipass effect in it by using sm3

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.