Reputation: 172
My project is an IOS app using OpenGL 2.0 with the GLKit. In a nutshell, i have a texture of star with a transparent background that i would like to apply on a square. The desired end result would be seeing a star; not a star on a square.
My current issue is that when i apply the texture on the square , i see a star with a colored square defined by its material color variables. What i would like is seeing only the star and having the rest of the square transparent.
The code is as follow:
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
[effectTmp prepareToDraw];
glEnableVertexAttribArray(GLKVertexAttribPosition);
glEnableVertexAttribArray(GLKVertexAttribTexCoord0);
glEnableVertexAttribArray(GLKVertexAttribNormal);
glVertexAttribPointer(GLKVertexAttribPosition, 3, GL_FLOAT, GL_FALSE, sizeof(ColoredVertexData3D), &vertexDataTexture[0].vertex);
glVertexAttribPointer(GLKVertexAttribNormal, 3, GL_FLOAT, GL_FALSE, sizeof(ColoredVertexData3D), &vertexDataTexture[0].normal);
glVertexAttribPointer(GLKVertexAttribTexCoord0, 2, GL_FLOAT, GL_FALSE, sizeof(ColoredVertexData3D), &vertexDataTexture[0].color);
glDrawArrays(GL_TRIANGLES, 0, [drawObjectTmp getSizeFromVertexIndicesArray]);
glDisableVertexAttribArray(GLKVertexAttribPosition);
glDisableVertexAttribArray(GLKVertexAttribTexCoord0);
glDisableVertexAttribArray(GLKVertexAttribNormal);
glDisable(GL_BLEND);
And the envMode is set to GLKTextureEnvModeDecal as below:
effect.texture2d0.envMode = GLKTextureEnvModeDecal;
Probably there is a big elephant in the corridor i am not seeing; and any help or pointer would be welcomed to help to see the star with its transparent square.
Cheers, Stéphane
Upvotes: 1
Views: 757
Reputation: 154
From the docs - GLKTextureEnvModeDecal uses the texture’s alpha component to blend the texture’s color with the input color.
I think you want GLKTextureEnvModeReplace.
Upvotes: 3