Max
Max

Reputation: 2749

Open GL ES texture: Set a transparent color || alpha of a color to zero

I've got a texture in which I want to set the alpha for a single color (e.g. (255,255,255)) to 0.

I use this calls at the moment (self.texture is a CCTexture2D from cocos2d)

glBindTexture(GL_TEXTURE_2D, self.texture.name);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_BYTE, baseAddress);

The texture displays perfectly. I hope you can help me.

Upvotes: 0

Views: 996

Answers (2)

Dervis Suleyman
Dervis Suleyman

Reputation: 101

Im not sure if i understood this and I'm fairly new to opengl but i think you want just one colour to be transparent can't you over lay two textures making one transeparent using the

gl.glblendfunc()

boolean SEE_THRU = true;
if (SEE_THRU) {
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glEnable(GL10.GL_BLEND);
gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE);
}

Upvotes: 1

Tim
Tim

Reputation: 35923

There's no way to do this with OpenGL commands. You'll have to either use a shader to filter for pixels of a certain color, or modify the pixel data at baseAddress in a pixel-by-pixel loop before uploading it to glTexImage2D.

Upvotes: 0

Related Questions