在OpenGL ES中,如何将绘图“剪切”为矩形?

时间:2013-04-03 01:14:41

标签: android graphics opengl-es 2d culling

我正在使用Android应用程序,我正在使用单个OpenGL ES实例。在某些情况下,我在其他所有内容上绘制一个自定义(矩形)对话框,滚动文本,线条等。对话框不占用整个屏幕,我正在绘制更大的内容比在对话框中滚动的对话框,就像一个选框。

当然,由于我正在绘制此对话框 last (在每个其他视图的顶部),我绘制的所有顶点都将可见,但我想告诉OpenGL 在对话框矩形之外绘制任何渲染命令。像这样......

Culling to rectangle

我的大多数绘图都是使用glDrawArrays(...)数组FloatBuffer完成的。我想要的是一种指定OpenGL的方法,我希望任何绘图在指定区域之外是不可见的。

我对剔除知之甚少,但这似乎与我正在寻找的非常相关。然而,剔除似乎只是为了跳过不会从3D中的相机视图中“看到”的三角形的绘制,而我想要“跳过”视口内任意矩形之外的任何三角形的绘制

1 个答案:

答案 0 :(得分:0)

如果您知道如何将纹理保存为类引用,则可以使用此方法,当您前后滚动或任何可以更改其中的参数时

public class TextureRegion {    
public final float u1, v1;
public final float u2, v2;
public final Texture texture;

public TextureRegion(Texture texture, float x, float y, float width, float height) {
    this.u1 = x / texture.width;
    this.v1 = y / texture.height;
    this.u2 = this.u1 + width / texture.width;
    this.v2 = this.v1 + height / texture.height;        
    this.texture = texture;
}
}
相关问题