Advertisement
Guest User

Untitled

a guest
Oct 25th, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.47 KB | None | 0 0
  1. package com.example.bogdankyuchukov.glexample;
  2.  
  3. import java.nio.ByteBuffer;
  4. import java.nio.ByteOrder;
  5. import java.nio.FloatBuffer;
  6. import java.nio.ShortBuffer;
  7.  
  8. import javax.microedition.khronos.opengles.GL10;
  9.  
  10. /**
  11.  * Created by Bogdan Kyuchukov on 25.10.2016.
  12.  */
  13.  
  14. public class GLTriangleEx {
  15.  
  16.     private float vertices[] = {0f, 1f,
  17.                                1f, -1f,
  18.                              -1f, -1f};
  19.  
  20.     private FloatBuffer verticesBuffer;
  21.     private short[] pointIndex = {0, 1, 2};
  22.     private ShortBuffer pointBuffer;
  23.  
  24.     public GLTriangleEx()
  25.     {
  26.         ByteBuffer byteBuffer = ByteBuffer.allocateDirect(vertices.length * 4);
  27.         byteBuffer.order(ByteOrder.nativeOrder());
  28.         verticesBuffer = byteBuffer.asFloatBuffer();
  29.         verticesBuffer.put(vertices);
  30.         verticesBuffer.position(0);
  31.  
  32.         ByteBuffer pointByteBuffer = ByteBuffer.allocateDirect(pointIndex.length * 2);
  33.         pointByteBuffer.order(ByteOrder.nativeOrder());
  34.         pointBuffer = pointByteBuffer.asShortBuffer();
  35.         pointBuffer.put(pointIndex);
  36.         pointBuffer.position(0);
  37.     }
  38.  
  39.     public void draw(GL10 gl)
  40.     {
  41.         gl.glFrontFace(GL10.GL_CW);
  42.         gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
  43.  
  44.         gl.glVertexPointer(2, GL10.GL_FLOAT, 0, verticesBuffer);
  45.         gl.glDrawElements(GL10.GL_TRIANGLES, pointIndex.length, GL10.GL_UNSIGNED_SHORT, pointBuffer);
  46.         gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
  47.     }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement