How can I use OpenGLES 1.1 (iPhone) to draw a texture, but only using the alpha to draw some color?
The result should be the exact same alpha mask from the original texture, with a single solid color inside instead of the original colors.
I am using glDrawArrays with glCoordPointer and glVertexPointer.
I think doing two passes, one with the texture and one with a solid color to to this. I just can’t seem to find the invert of glBlendFunc(GL_ZERO, GL_ONE_MINUS_SRC_ALPHA);.
Edit: after some more looking around, I thinks this should be possible to achieve using glTexEnvf. It’s just a matter of finding the right arguments.
As mentionned, glTexEnv is the way to go.
To replace the RGB components of your texture and keep its alpha untouched, you could try something like this (this code uses red as replacement color):
Here come some explanations.
When using GL_COMBINE, you have complete control on how the input/output of the different texture stages are combined together. In this case, we specify that we want to replace (GL_REPLACE) the RGB components of texture stage 0 with what comes from the previous stage (GL_PREVIOUS) which in this case is a single color (set with glColor4f).
We did not set anything special for the alpha component as we want the regular behavior.
Adding the following lines would have had the same effect as if not included (default behavior):