2

我是 Iphone opengl ES 编程的初学者。我有两个纹理,第一个是背景并占据全屏。我在第一张图片上打印第二张图片,但第二张图片的白色背景覆盖了部分背景。我希望在前景图片没有颜色(或白色)的地方可以看到背景。我无法弄清楚如何正确使用 glBlendFunc。

在打印第二张图像之前,我正在使用 Blending 与以下内容:

glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

图片位于:http ://www.flickr.com/x/t/0097002/photos/vjv2010/

4

1 回答 1

0

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 glBlendFunc properly.

More here: http://iphone-3d-programming.labs.oreilly.com/ch06.html

于 2010-06-25T06:13:48.157 回答