在opengl中, 可以开启模板测试功能,来限定某一部分是可画的,某一部分是不可画的。这可通过设置模板模式来控制哪部分是可画的, 有点类似在墙上喷字。
虽说剪刀测试也可以限定蓝屏的某一部分可画,但不适用于不规则的区域,不如模板测试灵活。下面提供一个Android模板测试的实例代码:
public class MyRenderer implements Renderer {
private Square square1 = null;
private FloatBuffer vertices = null;
// Step size in x and y directions
// (number of pixels to move each time)
private float x = 0;
private float y = 0;
private float xstep = 1.0f;
private float ystep = 1.0f;
// Keep track of windows changing width and height
private float windowWidth;
private float windowHeight;
public MyRenderer(Context ctx) {
square1 = new Square(ctx, false);
}
private void makeStencilPattern(GL10 gl) {
float dRadius = 0.1f;
ByteBuffer bb = ByteBuffer.allocateDirect(4000 * 4 * 2);
bb.order(ByteOrder.nativeOrder());
vertices = bb.asFloatBuffer();