I've been trying to draw a simple quad with OpenGL ES the entire day today without success. I'm using this for my 2D "engine" and want to draw it in orthographic projection. I've managed to do it with glDrawArrays but not with glDrawElements. Maybe some of you guys can see what I'm doing wrong.
Here's the code for my quad.
Using java Syntax Highlighting
- public class OpenGLSprite {
- public IntBuffer VertexBuffer;
- public IntBuffer ColorBuffer;
- public ByteBuffer IndexBuffer;
- private int one = 0x10000;
- int vertices[] = {
- -one, -one, one,
- one, -one, one,
- -one, one, one,
- one, one, one
- };
- int colors[] = {
- one, one, one, one,
- one, one, one, one,
- one, one, one, one,
- one, one, one, one,
- };
- byte indices[] = {
- 0, 1, 2, 1, 2, 3
- };
- public OpenGLSprite(){
- ByteBuffer vbb = ByteBuffer.allocateDirect(vertices.length*4);
- vbb.order(ByteOrder.nativeOrder());
- VertexBuffer = vbb.asIntBuffer();
- VertexBuffer.put(vertices);
- VertexBuffer.position(0);
- ByteBuffer cbb = ByteBuffer.allocateDirect(colors.length*4);
- cbb.order(ByteOrder.nativeOrder());
- ColorBuffer = cbb.asIntBuffer();
- ColorBuffer.put(colors);
- ColorBuffer.position(0);
- IndexBuffer = ByteBuffer.allocateDirect(indices.length);
- IndexBuffer.put(indices);
- IndexBuffer.position(0);
- }
- }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
And here's the drawing code: oglSprite is a OpenGLSprite instance.
Using java Syntax Highlighting
- gl.glClear(GL10.GL_COLOR_BUFFER_BIT|GL10.GL_DEPTH_BUFFER_BIT);
- gl.glMatrixMode(GL10.GL_PROJECTION);
- gl.glLoadIdentity();
- GLU.gluOrtho2D(gl, 0.0f, _width, 0.0f, _height);
- gl.glMatrixMode(GL10.GL_MODELVIEW);
- gl.glLoadIdentity();
- GLU.gluLookAt(gl, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);
- gl.glVertexPointer(3, GL10.GL_FIXED, 0, oglSprite.VertexBuffer);
- gl.glColorPointer(4, GL10.GL_FIXED, 0, oglSprite.ColorBuffer);
- gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_BYTE, oglSprite.IndexBuffer);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4
I've initialized with this code below:
Using java Syntax Highlighting
- gl.glClearColor(0.0f, 0.0f, 1.0f, 0.0f);
- gl.glEnable(GL10.GL_TEXTURE_2D);
- gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
- gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
- gl.glEnableClientState(GL10.GL_NORMAL_ARRAY);
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
My brain is really hurting at this point so any suggestions are appreciated.
Regards/Per


