Drawing a circle in opengl es android, squiggly boundaries

Posted by ladiesMan217 on Game Development See other posts from Game Development or by ladiesMan217
Published on 2012-03-27T06:24:37Z Indexed on 2012/03/27 11:41 UTC
Read the original article Hit count: 452

Filed under:
|
|
|

I am new to OpenGL ES and facing a hard time drawing a circle on my GLSurfaceView. Here's what I have so far.

the Circle Class

public class MyGLBall {

private int points=40;
private float vertices[]={0.0f,0.0f,0.0f};
private FloatBuffer vertBuff;


//centre of circle

public MyGLBall(){

    vertices=new float[(points+1)*3];
    for(int i=3;i<(points+1)*3;i+=3){
      double rad=(i*360/points*3)*(3.14/180);
      vertices[i]=(float)Math.cos(rad);
      vertices[i+1]=(float) Math.sin(rad);
      vertices[i+2]=0;
    }     
      ByteBuffer bBuff=ByteBuffer.allocateDirect(vertices.length*4);    
      bBuff.order(ByteOrder.nativeOrder());
      vertBuff=bBuff.asFloatBuffer();
      vertBuff.put(vertices);
      vertBuff.position(0);


}

public void draw(GL10 gl){
    gl.glPushMatrix();
    gl.glTranslatef(0, 0, 0);
//  gl.glScalef(size, size, 1.0f);
    gl.glColor4f(1.0f,1.0f,1.0f, 1.0f); 
    gl.glVertexPointer(3, GL10.GL_FLOAT, 0, vertBuff);
    gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, points/2);
    gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
    gl.glPopMatrix();
 }  

 }

I couldn't retrieve the screenshot of my image but here's what it looks like enter image description here

As you can see the border has crests and troughs thereby renering it squiggly which I do not want. All I want is a simple curve

© Game Development or respective owner

Related posts about android

Related posts about opengl-es