public void display(GLAutoDrawable drawable) { GL2 gl = drawable.getGL().getGL2(); // gl.glClear(GL.GL_COLOR_BUFFER_BIT); if (derefMethod == DRAWARRAY) { gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 6); } else if (derefMethod == ARRAYELEMENT) { gl.glBegin(GL2.GL_TRIANGLES); gl.glArrayElement(2); gl.glArrayElement(3); gl.glArrayElement(5); gl.glEnd(); } else if (derefMethod == DRAWELEMENTS) { int indices[] = new int[] {0, 1, 3, 4}; if (indicesBuf == null) { indicesBuf = GLBuffers.newDirectIntBuffer(indices.length); indicesBuf.put(indices); } indicesBuf.rewind(); gl.glDrawElements(GL2.GL_POLYGON, 4, GL2.GL_UNSIGNED_INT, indicesBuf); } gl.glFlush(); // gl calls from C example's mouse routine are moved here if (setupMethod == INTERLEAVED) setupInterleave(gl); else if (setupMethod == POINTER) setupPointers(gl); }
@Override protected void render(GL g) { GL2 gl = g.getGL2(); gl.glColor3f(.5f, .5f, .5f); // =======================================\\ // Retained Mode \\ // =======================================\\ gl.glEnableClientState(GL2.GL_VERTEX_ARRAY); gl.glVertexPointer(3, GL2.GL_FLOAT, 0, vertexBuffer); if (normal) { gl.glEnableClientState(GL2.GL_NORMAL_ARRAY); gl.glNormalPointer(GL2.GL_FLOAT, 0, normalBuffer); } if (texture) { gl.glEnableClientState(GL2.GL_TEXTURE_COORD_ARRAY); gl.glTexCoordPointer(2, GL2.GL_FLOAT, 0, textureBuffer); } else gl.glPolygonMode(GL2.GL_FRONT_AND_BACK, GL2.GL_LINE); for (IntBuffer face : faces) { if (face.capacity() == 3) gl.glDrawElements(GL2.GL_TRIANGLES, face.capacity(), GL2.GL_UNSIGNED_INT, face); else if (face.capacity() == 4) gl.glDrawElements(GL2.GL_QUADS, face.capacity(), GL2.GL_UNSIGNED_INT, face); else gl.glDrawElements(GL2.GL_POLYGON, face.capacity(), GL2.GL_UNSIGNED_INT, face); } gl.glDisableClientState(GL2.GL_VERTEX_ARRAY); if (normal) gl.glDisableClientState(GL2.GL_NORMAL_ARRAY); if (texture) gl.glDisableClientState(GL2.GL_TEXTURE_COORD_ARRAY); if (drawBox) bbox.draw(gl); }