Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 6 of 6

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

  1. #1
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    4

    Question 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:
    Code :
    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:
    Code :
    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

  2. #2
    Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    281
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    4
    Quote Originally Posted by Agent D View Post
    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!

  4. #4
    Member Regular Contributor Agent D's Avatar
    Join Date
    Sep 2011
    Location
    Innsbruck, Austria
    Posts
    281
    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:
    Code :
    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.

  5. #5
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    4
    Quote Originally Posted by Agent D View Post
    Code :
    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:
    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);
    Last edited by ldantona; 03-13-2014 at 05:12 AM.

  6. #6
    Junior Member Newbie
    Join Date
    Mar 2014
    Posts
    4
    Resolved with:
    Code :
    effect.texture2d0.envMode = GLKTextureEnvModeDecal;
    Thanks for your suggestion, the issue was definitely related to texture environment parameters!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •