I am a starter of Iphone opengl ES programming. I have two textures, the first one is the background and occupies the full screen. I am printing the second picture on top of the first image but the white background of the second image covers part of the background. I want the background to be visible where the foreground picture has no color(or White). I am unable to figure out how to use the glBlendFunc correctly.
before printing the second image I am using Blending with following:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
Images at: http://www.flickr.com/x/t/0097002/photos/vjv2010/
I want the background to be visible where the foreground picture has no color(or White).
You have two choices, the simplest one is to use alpha testing and add an alpha channel for your foreground image so that each white pixel (or no color zones) has a special value, let' say 0.0f and all other 1.0f.
Then when rendering the foreground you enable alpha testing with
glEnable(GL_ALPHA_TEST) and set alpha function with
glAlphaFunc(GL_GREATER, 0.5f) This will accept/draw only fragments that have an alpha value greater than 0.5f and discard/not draw all fragments that have an alpha value less than 0.5f.
Second choice is to use blending as you did, but you will need also to add extra alpha channel to your foreground and set
More here: http://iphone-3d-programming.labs.oreilly.com/ch06.html