I’m trying to draw an ellipse/circle in android, but I’m having trouble getting it to show up. I can do it fine in OpenGL in C (not in android) using an inefficent loop and glVertex, but OpenGL ES seems different enough that I’m somewhat lost. My ellipse class is below. I want to be able to define all the vertices in the constructor and draw them with the draw() method.
public class Ellipse {
private float _vertices[];
private FloatBuffer _vertex_buffer;
private int _segments;
public Ellipse(int segments, float width, float height) {
_vertices = new float[segments*2];
_segments = segments;
int count = 0;
for (float i = 0; i < 360.0f; i += (360.0f/_segments)) {
_vertices[count++] = (float)Math.cos(Math.PI/180.0f)*width;
_vertices[count++] = (float)Math.sin(Math.PI/180.0f)*height;
}
ByteBuffer vbb = ByteBuffer.allocateDirect(_vertices.length * 4);
vbb.order(ByteOrder.nativeOrder());
_vertex_buffer = vbb.asFloatBuffer();
_vertex_buffer.put(_vertices);
_vertex_buffer.position(0);
}
public void draw(GL10 gl) {
gl.glFrontFace(GL10.GL_CW);
gl.glVertexPointer(2, gl.GL_FLOAT, 0, _vertex_buffer);
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDrawArrays(gl.GL_LINE_LOOP, 0, _segments);
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
}
}
I figured out the problem. I left out the * i in the x/y calculation for the points.