Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

Thread: DIfferent Objects with different shaders in one scene

  1. #1
    Intern Contributor
    Join Date
    Sep 2006
    Location
    Delft
    Posts
    57

    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?

  2. #2
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,119

    Re: DIfferent Objects with different shaders in one scene

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

  3. #3
    Intern Contributor
    Join Date
    Sep 2006
    Location
    Delft
    Posts
    57

    Re: DIfferent Objects with different shaders in one scene

    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?

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    May 2005
    Location
    Prague, Czech Republic
    Posts
    924

    Re: DIfferent Objects with different shaders in one scene

    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...

  5. #5
    Senior Member OpenGL Pro k_szczech's Avatar
    Join Date
    Feb 2006
    Location
    Poland
    Posts
    1,119

    Re: DIfferent Objects with different shaders in one scene

    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.

  6. #6
    Intern Contributor
    Join Date
    Jun 2004
    Location
    Shanghai, China
    Posts
    79

    Re: DIfferent Objects with different shaders in one scene

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •