glDrawArrays

Can anyone point me to a working demo using glDrawArrays()? I can’t make it work…
Here is my code :

        gl.glEnableClientState(GL.GL_COLOR_ARRAY);
        gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
        float[] color = new float[]{0,1,0,0,1,0,0,1,0,0,1,0};
        FloatBuffer fbuf = ByteBuffer.allocateDirect(0).asFloatBuffer();

        fbuf.wrap(color);
        gl.glColorPointer(3,GL.GL_FLOAT,0,fbuf);
        float[] mypoint = new float[]{300,300,200,200,300,100,100,200};
        FloatBuffer ibuf = ByteBuffer.allocateDirect(0).asFloatBuffer();
        ibuf.wrap(mypoint);
        gl.glVertexPointer(2,GL.GL_FLOAT,0,ibuf);
        gl.glDrawArrays(GL.GL_LINE_LOOP,0,4);

[quote] float[] color = new float[]{0,1,0,0,1,0,0,1,0,0,1,0};
FloatBuffer fbuf = ByteBuffer.allocateDirect(0).asFloatBuffer();

        fbuf.wrap(color);

[/quote]
this is not going to work, first you allocate a direct-buffer with capacity 0, then you change it to a buffer that wraps an array, making it non-direct.

You have to do something like this:


FloatBuffer fBuf = ByteBuffer.allocateDirect(4).asFloatBuffer();
fBuf.put(color);

then render with the buffer.

Jan