Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.quew8.testapp;
- import java.nio.FloatBuffer;
- import java.nio.IntBuffer;
- import org.lwjgl.BufferUtils;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- import static org.lwjgl.opengl.GL11.*;
- import org.lwjgl.util.glu.GLU;
- /**
- *
- * @author Quew8
- */
- public class TestApplication {
- public static void init() throws LWJGLException {
- Display.setDisplayMode(new DisplayMode(800, 600));
- Display.setTitle("Test App");
- Display.create();
- glClearColor(1, 0, 0, 0);
- }
- public static void loop() {
- int error;
- FloatBuffer vertexBuffer = BufferUtils.createFloatBuffer(12 * 2);
- vertexBuffer.put(new float[] {
- 25, 45, //0
- 45, 65, //1
- 65, 45, //2
- 45, 25, //3
- 25, 85, //4
- 45, 105, //5
- 65, 85, //6
- 85, 105, //7
- 105, 85, //8
- 85, 65, //9
- 105, 45, //10
- 85, 25, //11
- });
- vertexBuffer.flip();
- FloatBuffer colourBuffer = BufferUtils.createFloatBuffer(12 * 3);
- colourBuffer.put(new float[] {
- 0, 1, 0, //0
- 0, 0, 1, //1
- 1, 0, 1, //2
- 0, 1, 0, //3
- 0, 1, 0, //4
- 0, 1, 0, //5
- 1, 0, 1, //6
- 0, 1, 0, //7
- 0, 1, 0, //8
- 0, 0, 1, //9
- 0, 1, 0, //10
- 0, 1, 0, //11
- });
- colourBuffer.flip();
- IntBuffer indexBuffer = BufferUtils.createIntBuffer(20);
- indexBuffer.put(new int[] {
- 0, 1, 2, 3, // Lower Left
- 4, 5, 6, 1, // Upper Left
- 7, 8, 9, 6, // Upper Right
- 10, 11, 2, 9, // Lower Right
- 1, 6, 9, 2, // Middle
- });
- indexBuffer.flip();
- while(!Display.isCloseRequested()) {
- glViewport(0, 0, 800, 600);
- glClear(GL_COLOR_BUFFER_BIT);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0, 140, 0, 140, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glVertexPointer(2, 8, vertexBuffer);
- glColorPointer(3, 12, colourBuffer);
- glDrawElements(GL_QUADS, indexBuffer);
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
- if( (error = glGetError()) != GL_NO_ERROR) {
- System.err.print(GLU.gluGetString(error));
- throw new RuntimeException("Something Bad Has Happened");
- }
- Display.update();
- Display.sync(60);
- }
- }
- public static void deinit() {
- Display.destroy();
- }
- public static void main(String[] args) throws LWJGLException {
- TestApplication.init();
- TestApplication.loop();
- TestApplication.deinit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement