I have tried following this and this to get vertex arrays from jogl to work and, although its not throwing any errors any more, it also isn't rendering anything but a blank screen. Here is the code:
public void init(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2(); // get the OpenGL graphics context
vertexArray = new float[]
{-100f,-100f,-50f,
100f,-100f,-50f,
100f,100f,-50f,
-100f,100f,-50f};
vertexBuffer = BufferUtil.newFloatBuffer(vertexArray.length);
for(int i=0;i<vertexArray.length;i++){
vertexBuffer.put(vertexArray[i]);
}
//vertexBuffer.put(vertexArray); //neither of these versions work
vertexBuffer.rewind();
indexArray = new int[]{0,1,2,3,0,1,2,3,0,1,2,3};
indexBuffer = BufferUtil.newIntBuffer(indexArray.length);
for(int i=0;i<indexArray.length;i++){
indexBuffer.put(indexArray[i]);
}
//indexBuffer.put(indexArray);
indexBuffer.rewind();
gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // set background (clear) color
gl.glClearDepth(1.0f); // set clear depth value to farthest
gl.glEnable(GL_DEPTH_TEST); // enables depth testing
gl.glDepthFunc(GL_LEQUAL); // the type of depth test to do
gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // best perspective correction
gl.glShadeModel(GL_SMOOTH); // blends colors nicely, and smoothes out lighting
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
gl.glLoadIdentity(); // reset the model-view matrix
gl.glColor3f(1f, 1f, 1f);
gl.glEnableClientState(GL_VERTEX_ARRAY);
gl.glVertexPointer(3, GL_FLOAT, 0, vertexBuffer);
gl.glDrawElements(GL_QUADS, indexArray.length, GL_UNSIGNED_INT, indexBuffer);
gl.glDisableClientState(GL_VERTEX_ARRAY);
gl.glTranslatef(0f, 0f, -60f);
GLUT glut = new GLUT();
//glut.glutSolidTeapot(1);
}
When I uncomment the teapot code I can see that, so I'm pretty sure its specific to glDrawElements. I have around zero confidence that I'm using the correct gl.GL_TYPE constants, but none of the one's I've tried have worked.