Enabling/disabling textures


I am wondering how you texture only certain parts of a scene. As a very simple example, I have as a fragment shader

uniform sampler2D texID;

void main(void)
{vec4 texColor = texture2D(texID,gl_TexCoord[0].st);
gl_FragColor = gl_Color * texColor;

In my code I have


draw some stuff


draw some more stuff

However, the entire scene is textured. Without binding an all white texture when I want parts of my scene to ‘not be textured’, how do I do this?
Are there glsl commands equivalent to glIsEnabled so that I could branch as needed

if (glIsEnabled(GL_TEXTURE_2D)){
gl_FragColor = gl_Color * texColor;


gl_FragColor = gl_Color;

Or is there some other preferred way?
Any help is appreciated. Thank-you.

The prefered way as far as I know is to bind another shader which does not perform texturing ( or to completly disable shaders )

So it can look like this:

bind your texturing shader

draw some stuff

disable shaders or bind other shader

draw some more stuff

Of course you can do this by branching inside the shader ( for example by passing some uniform variable to the shader which determines if the texture look-up should be done ). However branching is still quite slow on the GPU ( especialy in fragment shader since its SIMD )

I have never tried this, but you could set the sampler handle to 0.

Originally posted by Zulfiqar Malik:
I have never tried this, but you could set the sampler handle to 0.
Im not sure if I understand you correctly but setting the sampler to 0 means that you are reading a texture from the texture unit 0 so it would probably not help him much.

but maybe I just misunderstood what you meant :slight_smile:

Thanks for the replies. Enabling/disabling the shaders with glUseProgramObjectARB produced the desired results.

As a seperate question (too minor to start a new post), is it possible to use more than one shader program object at once. Example - a shadow map and a texture shader. Is it more/less desirable to seperate shaders when possible or to combine in a larger program, or is it just personal preference?

1.Only one shader can be active in given time.
2. On current hardware its usualy better to create separate shaders for most things ( it depends what you want to do ). I think that there are a lot of threads about this topic on this forum so you can find more detail when its better to create a new shader and when its possible to reuse an old one there.

and of course, this is where modular programming comes in - GLSL supports multiple source files, which you can combine to create specialised shaders simply by plugging your library of functions together in a specific way.

Yeah! Thanks the all above !

Let me think something more…

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