PDA

View Full Version : How do I apply a texture over a material in OpenGL ES?



ldantona
03-12-2014, 04:08 AM
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

Agent D
03-12-2014, 05:37 AM
What GL ES version are you using? In GL ES 1.x what you have to configure the texture environment parameters (http://www.khronos.org/opengles/sdk/1.1/docs/man/glTexEnv.xml).

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.

ldantona
03-12-2014, 07:41 AM
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.

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!

Agent D
03-12-2014, 03:31 PM
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.

ldantona
03-13-2014, 03:25 AM
glTexEnviv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );

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);

ldantona
03-13-2014, 06:51 AM
Resolved with:


effect.texture2d0.envMode = GLKTextureEnvModeDecal;

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