如何使用混合,使一个多边形透明?多边形、如何使用、透明

2023-09-05 05:09:04 作者:傲世

我有一个应用程序,它显示了两个多边形。我需要做的多边形逐渐看不见的,但对方必须是可见的。进出口工作使用OpenGL ES 1.1。我正在开发的机器人,但我认为其他平台会做同样的code有一些细微的变化。

I have a app that shows two polygons. I need to make progressively invisible one of the polygons, but the other must be visible. Im working with OpenGL ES 1.1. I'm developing for Android, but i think that other platforms will do the same code with some minor changes.

我怎么能做到这一点?

我知道,我必须与这些功能做到这一点:

I know that i must do it with these functions:

    glEnable (GL_BLEND); 
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

但我不知道我必须把它们以及如何使用它们使我的多边形逐渐透明。

But i dont know where i have to put them and how to use them to make my polygon progressively transparent.

推荐答案

貌似正确的混合功能有,画你的半透明的多边形前给他们打电话。 alpha值通常提供有颜色或texturemap(红,绿,蓝,阿尔法),和用于α-范围为0.0(透明)到1.0(不透明)给出的混合功能的上方。

Looks like the right blend functions there, call them before drawing your translucent polygon. The alpha value is typically supplied with the color or texturemap (Red, Green, Blue, Alpha), and the range for alpha is 0.0 (transparent) to 1.0 (opaque) given the blending function above.

另外请注意,半透明的对象是敏感的呈现顺序:通常情况下,你必须先画出所有的不透明物体,使用深度缓存为正常。然后,打开混合和设置深度缓存为只读,并绘制半透明物体后到前(绘制从相机最远的第一个)。这样的片段混合发生最远到最近的。

Also note that translucent objects are sensitive to render order: Typically you must draw all your opaque objects first, using the depth buffer as normal. Then, turn on blending and set the depth buffer to read-only, and draw your translucent objects back-to-front (draw the farthest from the camera first). This way the fragment blending happens farthest-to-nearest.