The opaque property is set to NO on my OpenGL view's CAEAGLLayer. There is a UIImageView behind the OpenGL view (the checkboard). A texture is drawn initially on the OpenGL view (the Emu bird photo). Now I want to draw another texture in the middle of the fame buffer. The new texture is completely black in color and the alpha changes from 0 to 255, from top to bottom.
This is my 2nd texture...
This is what I want...
This is what I get...
The checkboard texture is an UIImage in a UIImageView behind the EAGLView.
I do not want to disturb the RGB values in the frame buffer, I only want to write into the Alpha channel. I tried...
- glDisable(GL_BLEND) and glColorMask(0, 0, 0, 1)
- glEnable(GL_BLEND) and glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ZERO)
Nothing seems to work. The RGB values are always modified, the pixels become brighter.
If source RGBA is (r2, g2, b2, a2) and destination is (r1, g1, b1, a1). I want the final value to be (r1, g1, b1, a2) or preferably (r1, g1, b1, some_function_of(a1, a2)). How do I achieve this?
Here is my code...
Objective C code for drawing the second texture...
- (void) drawTexture {
GLfloat textureCoordinates[] = {
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
};
static const GLfloat imageVertices[] = {
-0.5f, -0.5f,
0.5f, -0.5f,
-0.5f, 0.5f,
0.5f, 0.5f,
};
[EAGLContext setCurrentContext:context];
glViewport(0, 0, backingWidth, backingHeight);
glUseProgram(program);
glActiveTexture(GL_TEXTURE2);
glBindTexture(GL_TEXTURE_2D, texture);
glEnable (GL_BLEND);
glBlendFuncSeparate(GL_ZERO, GL_ONE, GL_ONE, GL_ZERO);
glUniform1i(inputImageTexture, 2);
glVertexAttribPointer(position, 2, GL_FLOAT, 0, 0, imageVertices);
glVertexAttribPointer(inputTextureCoordinate, 2, GL_FLOAT, 0, 0, textureCoordinates);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindRenderbuffer(GL_RENDERBUFFER, viewRenderbuffer);
[context presentRenderbuffer:GL_RENDERBUFFER];
}
Vertex shader...
attribute vec4 position;
attribute vec4 inputTextureCoordinate;
varying vec2 textureCoordinate;
void main()
{
gl_Position = position;
textureCoordinate = inputTextureCoordinate.xy;
}
Fragment shader...
varying highp vec2 textureCoordinate;
uniform sampler2D inputImageTexture;
void main()
{
gl_FragColor = texture2D(inputImageTexture, textureCoordinate);
}