有没有办法将Android OpenGL ES 1.1绘制的对象组合在一起?

时间:2013-10-04 06:58:49

标签: android opengl-es

**我创建了一个类来绘制一行。↓↓

public class LINETEST{
float[] vertices = null;
private short[] indices = null;

public FloatBuffer verticesBuffer;
private ShortBuffer indexBuffer; 
private int LINE_NUMBER = 0;

public LINETEST() {

}

public void draw(GL10 gl) {

    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, verticesBuffer);
    gl.glLineWidth(2);
    gl.glColor4f(0f, 0f, 0f, 0f);

    gl.glDrawElements(GL10.GL_LINE_STRIP, indices.length, 
              GL10.GL_UNSIGNED_SHORT, indexBuffer); 

    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}

public void setBuffer() {

            ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length * 4);
            vbb.order(ByteOrder.nativeOrder());
            verticesBuffer = vbb.asFloatBuffer();
            verticesBuffer.put(vertices);
            verticesBuffer.position(0);

            ByteBuffer ibb = ByteBuffer.allocateDirect(indices.length * 2);
            ibb.order(ByteOrder.nativeOrder());
            indexBuffer = ibb.asShortBuffer();
            indexBuffer.put(indices);
            indexBuffer.position(0);            
}

public void setVertices(float[] verticesAl, short[] indicesAl, int number){

    this.vertices = verticesAl;
    this.indices = indicesAl;       
    this.LINE_NUMBER = number;

}

public int getLineNumber(){
    return this.LINE_NUMBER;
    }
}

**并且使用此类声明的数组对象的位置值以不同的方式给出。↓↓

linetest = new LINETEST[2000];

**每次绘制线条时我都会创建一个新对象。↓↓↓

public void setVertices(float[] vertice, short[] indice, int lineNumber){
    this.vertices = vertice;
    this.indices = indice;
    this.number = lineNumber;

 linetest[number] = new LINETEST();
 linetest[number].setVertices(vertices, indices, lineNumber);       
 linetest[number].setBuffer();  

}

**最后,我将绘制一个由渲染类的OnDrawFrame生成的对象。↓↓↓

@Override
public void onDrawFrame(GL10 gl) {
         if(vertices != null){
             if(linetest[number] != null){
                for(int i = 0; i<number; i++){
                    linetest[i].draw(gl);

                }
                 linetest[number].draw(gl);
             }

         }
}

**我可以声明为以这种方式绘制的线的一面吗?

**为什么我尝试做这项工作是因为我想把颜色放在以这种方式声明的表面内部。

1 个答案:

答案 0 :(得分:1)

如果我误解了这个问题,请原谅我,但我相信你试图画一个面(或多边形)而不是线条。如果您的顶点和索引缓冲区设置得恰当,那么您可能只需要将原语类型从GL_LINE_STRIP更改为类似GL_TRIANGLE_STRIP的类型。您需要确保为您选择的基本类型正确指定缓冲区,并且可能担心面部剔除。从那里你需要应用材质或纹理或两者来填充多边形。