circle

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

circle

Postby mikerizzo » Thu Mar 05, 2009 3:45 pm

hey guys,

im very new to the opengl es for android, you can call me a newb, because i am. I'm having difficulty drawing a circle, ive been looking at the sample code Cube.java and the CubeRender.java where it shows how to build a cube, so i thought id just have to pretty much remove the part of the cube and just implement a circle but its not working out to well for me. heres my code, if you guys have any idea what the issue is or a better way to do it, im open for suggestions.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4. public class Circle {
  5.  
  6.         private FloatBuffer   mVertexBuffer;
  7.  
  8.     private FloatBuffer   mColorBuffer;
  9.  
  10.     private ShortBuffer  mIndexBuffer;
  11.  
  12.     private final static int VERTS = 3;
  13.  
  14.        
  15.  
  16.         public Circle() {
  17.  
  18.        
  19.  
  20.                 ByteBuffer vbb = ByteBuffer.allocateDirect(VERTS * 3 * 4);
  21.  
  22.         vbb.order(ByteOrder.nativeOrder());
  23.  
  24.         mVertexBuffer = vbb.asFloatBuffer();
  25.  
  26.  
  27.  
  28.         ByteBuffer tbb = ByteBuffer.allocateDirect(VERTS * 2 * 4);
  29.  
  30.         tbb.order(ByteOrder.nativeOrder());
  31.  
  32.         mColorBuffer = tbb.asFloatBuffer();
  33.  
  34.  
  35.  
  36.         ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2);
  37.  
  38.         ibb.order(ByteOrder.nativeOrder());
  39.  
  40.         mIndexBuffer = ibb.asShortBuffer();
  41.  
  42.  
  43.  
  44.  
  45.  
  46.         float[] coords = {
  47.  
  48.                 // X, Y, Z
  49.  
  50.                 -0.5f, -0.25f, 0,
  51.  
  52.         };
  53.  
  54.  
  55.  
  56.         for (int i = 0; i < VERTS; i++) {
  57.  
  58.             for(int j = 0; j < 3; j++) {
  59.  
  60.                 mVertexBuffer.put(coords[i*3+j] * 2.0f);
  61.  
  62.             }
  63.  
  64.         }
  65.  
  66.  
  67.  
  68.         for (int i = 0; i < VERTS; i++) {
  69.  
  70.             for(int j = 0; j < 2; j++) {
  71.  
  72.                 mColorBuffer.put(coords[i*3+j] * 2.0f + 0.5f);
  73.  
  74.             }
  75.  
  76.         }
  77.  
  78.  
  79.  
  80.         for(int i = 0; i < VERTS; i++) {
  81.  
  82.             mIndexBuffer.put((short) i);
  83.  
  84.         }
  85.  
  86.  
  87.  
  88.         mVertexBuffer.position(0);
  89.  
  90.         mColorBuffer.position(0);
  91.  
  92.         mIndexBuffer.position(0);              
  93.  
  94.         }
  95.  
  96.          public void draw(GL10 gl) {
  97.  
  98.                 gl.glFrontFace(GL10.GL_CCW);
  99.  
  100.                 gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
  101.  
  102.                 //gl.glEnable(GL10.GL_TEXTURE_2D);
  103.  
  104.                 //gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mColorBuffer);
  105.  
  106.                 gl.glDrawElements(GL10.GL_LINE_STRIP, VERTS,
  107.  
  108.                         GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
  109.  
  110.             }
  111.  
  112.  
  113.  
  114. }
  115.  
  116.  
Parsed in 0.038 seconds, using GeSHi 1.0.8.4
mikerizzo
Once Poster
Once Poster
 
Posts: 1
Joined: Thu Mar 05, 2009 3:40 pm

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 4 guests