tags:

views:

51

answers:

1

Hi, I would like to blend up to 4 textures by using multitexturing feature in fixed pipe line. I can successful use 2 texture units but when I use more then two texture units there strange artifact occurred (some texture are missing or wrong texture coords). I don't know what I am doing wrong.

The code is very simple:

glGetIntegerv(GL_MAX_TEXTURE_UNITS, &TextureUnits); 
if (TextureUnits > 4)
    TextureUnits = 4;

// set textures parameters: texCoords and multitexturing combination
for (int j = 0; j < TextureUnits; ++j)
{
    glActiveTexture(GL_TEXTURE0 + j);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);   

    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
    glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);

    if (j == 0)
    {
        glEnable(GL_TEXTURE_2D);
        //glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
    }
    else
    {
        // Interpolate : 
        //      Arg0 * Arg2 + Arg1 * (1 - Arg2)
        // Set arguments to obtain the fallowing blending equation: 
        //      SRCrgb * SRCalpha + DSTrgb * (1 - SRCalpha)  
        glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
        glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);  
        glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_RGB, GL_TEXTURE);
        glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_RGB, GL_PREVIOUS);
        glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_RGB, GL_TEXTURE);
        glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
        glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
        glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);

        glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_INTERPOLATE);   
        glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE0_ALPHA, GL_TEXTURE);
        glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE1_ALPHA, GL_PREVIOUS);
        glTexEnvi(GL_TEXTURE_ENV, GL_SOURCE2_ALPHA, GL_TEXTURE);
        glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
        glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
        glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
    }

    glEnableClientState(GL_TEXTURE_COORD_ARRAY);

    glClientActiveTexture(GL_TEXTURE0 + j);
    glTexCoordPointer(2, GL_FLOAT, sizeof(Vertex), &Mesh->Vertices[0].TexCoords);
}

...

for (int i = 0; i < TextureUnits; ++i)
{
    glActiveTexture(GL_TEXTURE0 + i);
    glDisable(GL_TEXTURE_2D);
}

// use multitexturing and mulipasses when there are needed. 
count = ; // number of textures to blend It could be from 1 to 4.
do
{
    tex = 0;
    while (index < count && tex != TextureUnits)
    {           
        texture = textures[index];

        glActiveTexture(GL_TEXTURE0 + tex);         
        glEnable(GL_TEXTURE_2D);

        setTextureMatrix(texture);

        glBindTexture(GL_TEXTURE_2D, texture->getGLTexture());

        index++;
        tex++;
    }

    if (tex < TextureUnits)
    {
        glActiveTexture(GL_TEXTURE0 + tex);
        glDisable(GL_TEXTURE_2D);
    }

    glDrawElements(...);

} while (index < count);
A: 

after this:

glGetIntegerv(GL_MAX_TEXTURE_UNITS, &TextureUnits); 

what is the value of TextureUnits? I think it is 2.

Kuscsikp
No, it is 4. So, I am in the fog. Could be a driver issue?
gaspode
Maybe, What are the values for "GL_MAX_TEXTURE_COORDS", "GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS"?
Kuscsikp