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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| float[] vertexArray = {0, 0, 1, 1, 0, -1, -1, 0, -1, 0, 1, 0};
float[] colorArray = {0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0};
int[] geometryArray = {3, 0, 1, 3, 2, 0, 3, 1, 2};
FloatBuffer vertexBuffer; FloatBuffer colorBuffer;
public void init (...) { gl.glEnableClientState(GL.GL_VERTEX_ARRAY); gl.glEnableClientState(GL.GL_COLOR_ARRAY);
ByteBuffer buffer = ByteBuffer.allocateDirect( vertexArray.length * 4) ; buffer = buffer.order(ByteOrder.nativeOrder()); vertexBuffer = buffer.asFloatBuffer();
buffer = ByteBuffer.allocateDirect( colorArray.length * 4) ;
buffer = buffer.order(ByteOrder.nativeOrder()); colorBuffer = buffer.asFloatBuffer();
vertexBuffer.put(vertexArray); colorBuffer.put(colorArray);
vertexBuffer.position(0); gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertexBuffer);
colorBuffer.position(0); gl.glColorPointer(3, GL.GL_FLOAT, 0, colorBuffer);
public void display(...) { gl.glDrawRangeElements(GL.GL_TRIANGLES, 0, 3, 9, GL.GL_UNSIGNED_INT, geometryArray);
|