1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| public void gameLoop(){ final int vertices = 8; final int vertexSize = 3; final int colorSize = 3; FloatBuffer vertexData = BufferUtils.createFloatBuffer(vertices * vertexSize); vertexData.put(new float[]{-0.5f, 0.5f, 0.0f, 0.5f, 0.5f, 0.0f, 0.5f, -0.5f, 0.0f, -0.5f, -0.5f, 0.0f}); vertexData.flip();
FloatBuffer colorData = BufferUtils.createFloatBuffer(vertices * colorSize); colorData.put(new float[]{1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f}); colorData.flip(); while(running) { update(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); GL11.glTranslatef(0.0f, 0.0f, -6.0f); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_COLOR_ARRAY); glVertexPointer(vertexSize, 0, vertexData); glColorPointer(colorSize, 0, colorData); glDrawArrays(GL_QUADS, 0, vertices); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); Display.sync(60); Display.update(); } Display.destroy(); } |