im very new to the opengl es for android, you can call me a newb, because i am. I'm having difficulty drawing a circle, ive been looking at the sample code Cube.java and the CubeRender.java where it shows how to build a cube, so i thought id just have to pretty much remove the part of the cube and just implement a circle but its not working out to well for me. heres my code, if you guys have any idea what the issue is or a better way to do it, im open for suggestions.
Using java Syntax Highlighting
- public class Circle {
- private FloatBuffer mVertexBuffer;
- private FloatBuffer mColorBuffer;
- private ShortBuffer mIndexBuffer;
- private final static int VERTS = 3;
- public Circle() {
- ByteBuffer vbb = ByteBuffer.allocateDirect(VERTS * 3 * 4);
- vbb.order(ByteOrder.nativeOrder());
- mVertexBuffer = vbb.asFloatBuffer();
- ByteBuffer tbb = ByteBuffer.allocateDirect(VERTS * 2 * 4);
- tbb.order(ByteOrder.nativeOrder());
- mColorBuffer = tbb.asFloatBuffer();
- ByteBuffer ibb = ByteBuffer.allocateDirect(VERTS * 2);
- ibb.order(ByteOrder.nativeOrder());
- mIndexBuffer = ibb.asShortBuffer();
- float[] coords = {
- // X, Y, Z
- -0.5f, -0.25f, 0,
- };
- for (int i = 0; i < VERTS; i++) {
- for(int j = 0; j < 3; j++) {
- mVertexBuffer.put(coords[i*3+j] * 2.0f);
- }
- }
- for (int i = 0; i < VERTS; i++) {
- for(int j = 0; j < 2; j++) {
- mColorBuffer.put(coords[i*3+j] * 2.0f + 0.5f);
- }
- }
- for(int i = 0; i < VERTS; i++) {
- mIndexBuffer.put((short) i);
- }
- mVertexBuffer.position(0);
- mColorBuffer.position(0);
- mIndexBuffer.position(0);
- }
- public void draw(GL10 gl) {
- gl.glFrontFace(GL10.GL_CCW);
- gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
- //gl.glEnable(GL10.GL_TEXTURE_2D);
- //gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, mColorBuffer);
- gl.glDrawElements(GL10.GL_LINE_STRIP, VERTS,
- GL10.GL_UNSIGNED_SHORT, mIndexBuffer);
- }
- }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4

