1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
private void drawLine(GL10 gl) {
//画坐标轴
float[] vertexArr1 = {
-1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, -1.0f, 0.0f
};
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertexArr1.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());
FloatBuffer floatBuffer1 = byteBuffer.asFloatBuffer();
floatBuffer1.put(vertexArr1);
floatBuffer1.position(0);
gl.glColor4f(0.0f, 1.0f, 0.0f, 0.0f);
gl.glLineWidth(5.0f);
gl.glLoadIdentity();
gl.glTranslatef(0, 0, -4);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, floatBuffer1);
gl.glDrawArrays(GL10.GL_LINES, 0, 4);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
//4条线
float[] vertexArr2 = {
-0.5f, -0.5f, 0f,
0.0f, .5f, 0f,
0.5f, -0.5f, 0f,
0.9f, -0.0f, 0f,
};
byteBuffer = ByteBuffer.allocateDirect(vertexArr2.length * 4);
byteBuffer.order(ByteOrder.nativeOrder());
FloatBuffer floatBuffer2 = byteBuffer.asFloatBuffer();
floatBuffer2.put(vertexArr2);
floatBuffer2.position(0);
gl.glColor4f(1.0f, 0.0f, 0.0f, 0.0f);
gl.glLineWidth(20.0f);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, floatBuffer2);
gl.glDrawArrays(GL10.GL_LINE_STRIP, 0, 4);
}
|