Very odd problem with glActiveTexture..

Im not even sure if this belongs in this section but here goes:

Im having a very weird issue with glActiveTexture. Code:


       glActiveTexture(GL_TEXTURE0);
        glEnable(GL_TEXTURE_2D);

        glBindTexture(GL_TEXTURE_2D, texture.TextureID);

        glBegin(GL_QUADS);
        glColor3f(r, g, b);

        glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, 0.0f);
        glTexCoord2f(1.0f, 0.0f); glVertex3f(1.0f, -1.0f, 0.0f);
        glTexCoord2f(1.0f, 1.0f); glVertex3f(1.0f, 1.0f, 0.0f);
        glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);

        glEnd();
        glBindTexture(GL_TEXTURE_2D, 0);
        glActiveTexture(GL_TEXTURE0);

Where r, g, b, and texture are passed in as arguments. If I use GL_TEXTURE0, the texture displays fine. If I use GL_TEXTURE1 through GL_TEXTURE3, the texture is a single washed out color (The color depends on the color of the texture). If i use anything beyond GL_TEXTURE4, the image is pure white.

Nothing else has changed in between tests. What gives?

The fixed function texture environment pipeline applies a math function to the value sampled from the each texture in order. That is, it does the texture environment operation from GL_TEXTURE0, then from GL_TEXTURE1, then from GL_TEXTURE2, etc. Each operation feeds into the next.

If you really want the flexibility to use arbitrary texture units however you want, you will need to use shaders.

If i use anything beyond GL_TEXTURE4, the image is pure white.

That’s probably because GL_MAX_TEXTURE_UNITS is 4 for your implementation. That means you can’t used fixed-function texture environment logic with more than 4 textures in a single pass.

That makes sense, however 4 is prohibitively low.

Ive read (on another thread here) that using shaders will give you access to the full range, but is there any way to check what that range is?

Ive read (on another thread here) that using shaders will give you access to the full range, but is there any way to check what that range is?

GL_MAX_TEXTURE_IMAGE_UNITS. That’s the maximum number across all shader stage. Each shader stage has its own limit, but this enum gets you the sum total of all shader stages.

In general, for DX9-class hardware, the limit is 8 for fragment shaders and 4 for vertex shaders. In DX10 and above, it’s 16 for each stage.

GL_MAX_TEXTURE_IMAGE_UNITS is actually the number of units available to the fragment stage.

GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS is the sum across all stages.

If I use GL_TEXTURE1 through GL_TEXTURE3, the texture is a single washed out color 

you want to use
glMultiTexCoord2f

instead of glTexCoord2f

are you on NVIDIA? Check this out - I believe it’s still relevant: http://developer.nvidia.com/object/General_FAQ.html#t6

Yes i am, and that site helps tremendously.

Thanks for all the answers, it seems to make sense now.