PDA

View Full Version : How to properly use glTexEnv with tex. units...



Nowhere-01
03-16-2011, 07:03 AM
Hey. Caused mainly by lack of any certain info about opengl call order, some questions...

1st problem is, for some unknown reason glTexEnv acts retarded: if i change texenv mode for any of object types it screws up everything if i use fixed pipeline. Practically, it looks like every gltexenv works globally. For example:


glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glBindTexture(GL_TEXTURE_2D, NullObj);

...Render Poly's...

glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, 0);

Every object type in my program has simillar render code(really more complex, but it mostly repeats pieces of code above with some variations). So if i change

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);

to

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ADD);

Every object goes white.

if i replace it with
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);

it inverts colors for every object.

Do i unbind textures correctly? Do i bind them correctly? What's wrong?

Little more complex example of render code:


if(ShaderSupport)
{
glUniform1fARB(CoreAlpha, _a);
glUniform1fARB(Interpolation, _i);
glUniform1iARB(ElementType, _Type);

if(DTex == 1)
{
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, DTxO);
if(TStorage[DTid].Content.depth == 24)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
else
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glUniform1iARB(colorMap, 0);
}

if(UTex == 1)
{
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, UTxO);
if(TStorage[UTid].Content.depth == 24)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
else
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);
glUniform1iARB(activeMap, 1);
}
else
{
glUniform1fARB(Interpolation, 0.0);
}

}
else
{
if(UTex == 1 && _i > 0.4)
{
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, UTxO);
if(TStorage[UTid].Content.depth == 24)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
else
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ALPHA);
}
else
{
if(DTex == 1)
{
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, DTxO);
if(TStorage[DTid].Content.depth == 24)
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
else
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ALPHA);
}
}
}

...Render....

glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);

glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D, NULL);

With GLSL it's ok(Mostly, except i can't make it render polygons without texture, it just ignores them despite i do explicitly set fragment color and alpha to 1.0 in that case in my frag.shader). But with fixed pipeline if i change any of TexEnv results are upredictable and they affect every object(even if it has alternate render code). Any help?

Hmmm... Is it right to add

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

before

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_ALPHA);

?
Because it looks right, but does it work properly and could it lead to some nasty bugs later? I'm not shure.

_arts_
03-16-2011, 07:57 AM
GL_ALPHA is not a valid value for this function.

Nowhere-01
03-16-2011, 08:01 AM
Umm...If i remove TexEnv with GL_ALPHA and leave only

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); for fixed pipeline mode, texture alpha still works. Is it default behaviour or weird bug?