How do I apply a texture over a material in OpenGL ES?

Hi all,

how can I apply a texture over a material with GLKit in an iOS project?

I’ve set up an object with the following material:

GLKBaseEffect *effect;
effect.colorMaterialEnabled = false;
effect.material.ambientColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0);
effect.material.diffuseColor = GLKVector4Make(251.0/255.0, 95.0/255.0, 96.0/255.0, 1.0);

and it is correctly rendered with a pink color.

However, when I apply a texture with:

GLKTextureInfo * info = [GLKTextureLoader textureWithCGImage:...];
effect.texture2d0.name = info.name;
effect.texture2d0.enabled = true;

where the texture is transparent I cannot see the material underneath, but the object is rendered transparent instead of being pink.

Any hint is really appreciated!

Thanks,
DAN

What GL ES version are you using? In GL ES 1.x what you have to configure the texture environment parameters.

In GL ES 2.x and 3.x you would do the combination of diffuse color and texture value in your fragment shader anyway and replace mutliplication with blending.

[QUOTE=Agent D;1258333]
In GL ES 2.x and 3.x you would do the combination of diffuse color and texture value in your fragment shader anyway and replace mutliplication with blending.[/QUOTE]

Hi Agent D,

I’m working with GL ES 2.x.
At the moment I’m not using any shader, just basic GL instructions; could you give me a few more details about what I should do?

Thanks a lot!

What you want to do sounds like blending an RGBA texture onto a triangle with a solid color, or another set of textures.

From looking over the man page, I would say you have to set the texture environt ment mode for the texture you want to blend like this:


glTexEnviv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );

However, this is just a guess from a brief look at the man page. I myself have never used texture environment settings before.

With that line of code the object disappears.
Should I enable anything else?

Here’s my code:


glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
        
effect.texture2d0.name = info.name;
effect.texture2d0.enabled = true;

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

Resolved with:


effect.texture2d0.envMode = GLKTextureEnvModeDecal;

Thanks for your suggestion, the issue was definitely related to texture environment parameters! :slight_smile: