tags:

views:

83

answers:

2

i have several objects on my scene. i want to apply my shader to one of them only. Environment: OpenGL 2.0, C++, GLUT, GLEW.

+1  A: 

In your drawcall draw that object with that shader and draw the other ones without it.. can't really be any more simple than that ;P You could use enums in your object class where you can specify shaders that are enabled for that object and only pass them through that shader when they are supposed to.. of course if it's a fullscreen pixelshader then you're in trouble as it processes every pixel and renders a new image to display. Unless you have a way of passing the object as a parameter and a algoritm to only apply the alterations at the location of that object.

Jonas B
+3  A: 

The shader program is only in effect for as long as it is installed. Only the draw calls you make while the program is installed will use the shader. You must install your shader, draw your object, and then uninstall the shader.

Edit: By "install" the shader I mean use glUseProgram with your shader's handle. By "uninstall" I mean either installing another shader or calling glUseProgram with an argument of 0. See glUseProgram. My "install/uninstall" terminology comes from there.

Mike Daniels
Ugh what are you talking about? Install? Uninstall? What exactly is your definition of a shader?
Jonas B
how do i uninstall shader? by glDetachShader? is there something opposite to glUseProgram -> glDontUseProgram?
Andrey
@Jonas, @Andrey, My "install"/"uninstall" terminology comes from the documentation of `glUseProgram`. I edited my response to clarify.
Mike Daniels
`glUseProgram(0)` is the correct way to "uninstall" a shader, I believe.
Xavier Ho
damn, that works!!! many thx!!!
Andrey
Ok, my appologies
Jonas B