I am learning about OpenGL API on Android. I just drew a circle. Below is the code I used.

public class MyGLBall {

private int points=360;
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+1]=(float) Math.sin(rad);
      ByteBuffer bBuff=ByteBuffer.allocateDirect(vertices.length*4);    


public void draw(GL10 gl){
    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.glDrawArrays(GL10.GL_TRIANGLE_FAN, 0, points/2);


It is actually taken directly from here The circle looks pretty good. But now I want to make the boundary of the circle smooth. What changes do I need to make to the code? Or do I need to use some other technique for drawing the circle?


  • \$\begingroup\$ See the function I wrote for that answer. Just increase the sides variable to something larger. The circle will get smoother. \$\endgroup\$
    – House
    Commented Jan 17, 2013 at 21:44
  • \$\begingroup\$ This sounds more like an aliasing issue to me than the number of sides of the polygon. So you might want to look at this question/answers: stackoverflow.com/questions/4934367/… \$\endgroup\$
    – bummzack
    Commented Jan 18, 2013 at 7:14

2 Answers 2


With polygon-based graphics, the only option you have to better approximate a circle is to subdivide further. 720 triangles will result in a smoother circle, but 1440 will give you an even smoother circle, but 2880...

A perfect circle, created using polygons, would require an infinite amount of infinitesimally small polygon sections (in other words, it just isn't possible, in theory). Practically, however, if you subdivide enough times, you may reach a point where the length of the polygon section is equal to or smaller in size than a pixel, meaning that, for purposes of your framebuffer, you have achieved a "perfect" circle.

The other option, of course, is to cheat: render a flat quadrilateral oriented perpendicular to the camera, and texture it with an image of a sphere. 2 triangles, 1 texture of sufficient resolution: smooth circle, and a hell of a lot less vertices for your GPU to worry about.

  • \$\begingroup\$ +1 Sort of like a Riemann sum. Since we can only use polygons, we just have to use a lot to get a better approximation. \$\endgroup\$
    – House
    Commented Jan 17, 2013 at 21:48
  • \$\begingroup\$ Thanks slyfox, Byte56 for your answers and comments. I saw that if I increase the number of vertices, the smoothness increases. But now I have reached a point from where it cannot be increased. I am thinking about using an external image. But sure your comments helped me learn something. \$\endgroup\$ Commented Jan 18, 2013 at 0:24

If you want to do vector graphics with OpenGL, you should do taht in shaders. E.g.

gl_FragColor = ( length(gl_FragCoord.xy) < 0.5 ) ? vec4(1,1,1,1) : vec4(0,0,0,1);

You can do some "supersampling" to make it smooth, or analytically compute the area of pixel, which is overlapped by circle.

BTW. there is also OpenVG API out there.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .