glDrawArrays doesn’t work, it just shows a window with black background, nothing on it!
I searched this forum and used the “BufferUtil.newFloatBuffer” to generate the ordered floatbuffer, but still can not figure out where the problem is.
Anybody can help me check it and give me a help? Thanks very much!
I’m really screwed and can’t finish it before the deadline :’(
public void display(GLAutoDrawable drawable) {
GL gl = drawable.getGL();
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glLoadIdentity();
gl.glColor3f(1F, 0F, 0F);
// create FloatBuffer and store data in it
float vs[] = {0, -0.1f, -0.1f, 0, -0.1f, 0.1f, 0, 0.1f, 0.1f, 0, 0.1f, -0.1f};
FloatBuffer vertexBuffer = BufferUtil.newFloatBuffer(vs.length);
vertexBuffer.clear();
vertexBuffer.put(vs);
vertexBuffer.flip();
vertexBuffer.rewind();
// enable vertex array
gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
// give pointer to data
gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertexBuffer);
gl.glBegin(GL.GL_QUADS);
// draw
gl.glDrawArrays(GL.GL_QUADS, 0, 3);
// gl.glDrawElements(GL.GL_QUADS, 3, GL.GL_QUADS, vertexBuffer);
gl.glEnd();
}
another question, when I use the gl.glDrawElements(GL.GL_QUADS, 3, GL.GL_QUADS, vertexBuffer),
I even can not compile it. It says:
“May not call this between glBegin and glEnd”
So, where can I call glDrawElements? Thanks!!!