Drawing Polygons and Ellipses using LWJGL

hi can anyone help me with this… i am new to OpenGL… i’m currently using LWJGL… actually i am modifying
GTGE interface for LWJGL… when examining the code, i found that there is no implementation for drawing arcs, circles, etc.

I am confused with how OpenGL works so I find it hard to solve this by myself… any help is appreciated… thanks in advance :slight_smile:

OpenGL doesn’t any primitive drawing other than point, line, filled triangle and filled quad. (I would say stick with triangle and avoid quad).
For any other shape, you have decompose it :

  • line polygon = several lines (easy)
  • filled polygon = several triangles (tesselation, see org.lwjgl.util.glu I have never used it but I use my own code for this)
  • filled arc and circle can be done with triangles and shader

May be you should take a look to slick2d. It is library over lwjgl that implements a lot of 2d stuff.

To draw a circle, you can use a triangle fans.


GL11.glPushMatrix();
GL11.glTranslatef(x, y, 0);
GL11.glScalef(radius, radius, 1);

GL11.glBegin(GL11.GL_TRIANGLE_FAN);
GL11.glVertex2f(0, 0);
for(int i = 0; i <= NUM_PIZZA_SLICES; i++){ //NUM_PIZZA_SLICES decides how round the circle looks.
    double angle = Math.PI * 2 * i / SUBDIVISIONS;
    GL11.glVertex2f((float)Math.cos(angle), (float)Math.sin(angle));
}
GL11.glEnd();

GL11.glPopMatrix();

Coded in forum post, there might be typos…