Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.bogdankyuchukov.glexample;
- import java.nio.ByteBuffer;
- import java.nio.ByteOrder;
- import java.nio.FloatBuffer;
- import java.nio.ShortBuffer;
- import javax.microedition.khronos.opengles.GL10;
- /**
- * Created by Bogdan Kyuchukov on 25.10.2016.
- */
- public class GLTriangleEx {
- private float vertices[] = {0f, 1f,
- 1f, -1f,
- -1f, -1f};
- private FloatBuffer verticesBuffer;
- private short[] pointIndex = {0, 1, 2};
- private ShortBuffer pointBuffer;
- public GLTriangleEx()
- {
- ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
- byteBuffer.order(ByteOrder.nativeOrder());
- verticesBuffer = byteBuffer.asFloatBuffer();
- verticesBuffer.put(vertices);
- verticesBuffer.position(0);
- ByteBuffer pointByteBuffer = ByteBuffer.allocateDirect(pointIndex.length * 2);
- pointByteBuffer.order(ByteOrder.nativeOrder());
- pointBuffer = pointByteBuffer.asShortBuffer();
- pointBuffer.put(pointIndex);
- pointBuffer.position(0);
- }
- public void draw(GL10 gl)
- {
- gl.glFrontFace(GL10.GL_CW);
- gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glVertexPointer(2, GL10.GL_FLOAT, 0, verticesBuffer);
- gl.glDrawElements(GL10.GL_TRIANGLES, pointIndex.length, GL10.GL_UNSIGNED_SHORT, pointBuffer);
- gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement