开发者

What is a simple way to brighten textures mapped to a quad in OpenGL ES?

I'm displaying 2D sprites that are built using multiple textures (with transparency) applied to quads. I have enabled the color array for glDrawArrays and know how to use this to change the ratio of each color and to dim the textures (ie. reducing all colors the same amount).

This is all done using the premultiplied alpha and the following:

glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

Is there a simple way to brighten a texture as well?

I tried using GL_ADD, but this cau开发者_JAVA技巧ses the entire quad to become visible (ie. pixels that were previously transparent are not anymore).

Thanks.


This is quite easy: draw another quad over the region you want brightened, with that overlay quad using

glBlendFunc(GL10.GL_DST_COLOR, GL10.GL_ONE);

which effectively means you take the underlying color (dst, GL_ONE) as it is, and add another fraction of the same color (src, GL10.GL_DST_COLOR).

The fraction you add is specified by the color of the quad, so you can now tweak the brightness by setting the overlay quad's vertex colors to {0.0f, 0.0f, 0.0f} (no brightening) to {1.0f, 1.0f, 1.0f} ('doubling' the brightness). Of course you can increase individual colors' brightness by tweaking the factors as well.

Good luck!

Cheers, Aert.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜