PDA

View Full Version : Very odd problem with glActiveTexture..



Grimfate202
03-28-2011, 07:39 PM
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?

Alfonse Reinheart
03-28-2011, 08:18 PM
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.

Grimfate202
03-28-2011, 08:36 PM
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?

Alfonse Reinheart
03-28-2011, 09:30 PM
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.

arekkusu
03-28-2011, 10:50 PM
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.

dukey
03-29-2011, 02:05 AM
If I use GL_TEXTURE1 through GL_TEXTURE3, the texture is a single washed out color

you want to use
glMultiTexCoord2f

instead of glTexCoord2f

mhagain
03-29-2011, 02:26 AM
are you on NVIDIA? Check this out - I believe it's still relevant: http://developer.nvidia.com/object/General_FAQ.html#t6

Grimfate202
03-29-2011, 02:36 PM
Yes i am, and that site helps tremendously.

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