You seem to have a lot of this mixed up. LWJGL and openGL really have nothing to do with this and whether you use glDrawArrays
or glBegin
doesn't matter.
There is no drawCircle
function anywhere in LWJGL, you have to draw your circle using triangles, if you want to be more efficient a triangle fan is better.
Here is a method I wrote which gives you the verticies for a filled arc (specify 0 and 360 for startingAngleDeg
and endAngleDeg
for a full circle).
public static float[] getFilledArcVertexes(float x, float y, float r, double startingAngleDeg, double endAngleDeg, int slices) {
if(startingAngleDeg < 0)
Heatstroke.error("Starting angle cannot be smaller than 0");
if(endAngleDeg >= 720)
Heatstroke.error("End angle cannot be greater or equal to than 720");
if(endAngleDeg < startingAngleDeg)
Heatstroke.error("End angle cannot be smaller than starting angle");
int radius = (int) r;
double arcAngleLength = (endAngleDeg - startingAngleDeg) / 360f;
float[] vertexes = new float[slices*6+6];
double initAngle = Math.PI / 180f * startingAngleDeg;
float prevXA = (float) Math.sin(initAngle) * radius;
float prevYA = (float) Math.cos(initAngle) * radius;
for(int arcIndex = 0; arcIndex < slices+1; arcIndex++) {
double angle = Math.PI * 2 * ((float)arcIndex) / ((float)slices);
angle += Math.PI / 180f;
angle *= arcAngleLength;
int index = arcIndex * 6;
float xa = (float) Math.sin(angle) * radius;
float ya = (float) Math.cos(angle) * radius;
vertexes[index] = x;
vertexes[index+1] = y;
vertexes[index+2] = x+prevXA;
vertexes[index+3] = y+prevYA;
vertexes[index+4] = x+xa;
vertexes[index+5] = y+ya;
prevXA = xa;
prevYA = ya;
}
return vertexes;
}
This is a pretty badly coded method made by myself in a rush. Make sure you understand it before you use it however, here is a breakdown of how it works:
- Work out the initial angle (only applies if drawing an arc)
- Loop over every number from 0 to
slices
, this parameter is the level of detail you want your circle to have, higher means more triangles however once you reach a certain level no more detail will be added and will just eat up cpu time. - Work out the angle in radians
- Use
Math.sin
andMath.cos
to work out the x and y values for that particular point on the outside of the circle - Add the appropriate vertexes to the
vertexes
array
This will return an array of floats that should be used with GL_TRIANGLES
, you could try improving it to use GL_TRIANGLE_FAN