** 我创建了一个类来画一条线。↓↓
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];
**而且每次画线我都会创建一个新对象。↓↓↓</p>
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 生成的对象。↓↓↓</p>
@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);
}
}
}
** 我可以声明为以这种方式绘制的线的一个面吗?
** 为什么我尝试做这项工作是我想把颜色放在以这种方式声明的表面内部。