Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.test;
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.nio.ByteBuffer;
- import java.nio.FloatBuffer;
- import org.lwjgl.BufferUtils;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.LWJGLUtil;
- import org.lwjgl.input.Keyboard;
- import org.lwjgl.opengl.ContextAttribs;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- import org.lwjgl.opengl.GL11;
- import org.lwjgl.opengl.GL15;
- import org.lwjgl.opengl.GL20;
- import org.lwjgl.opengl.GL30;
- import org.lwjgl.opengl.PixelFormat;
- import org.lwjgl.util.glu.GLU;
- public class Main {
- // Entry point for the application
- public static void main(String[] args) {
- System.setProperty("org.lwjgl.librarypath",
- new File(new File(System.getProperty("user.dir"), "native"),
- LWJGLUtil.getPlatformName()).getAbsolutePath());
- new Main();
- }
- private final String WINDOW_TITLE = "CubeTest";
- private final int WIDTH = 640;
- private final int HEIGHT = 360;
- private Container cont;
- public Main() {
- this.setupOpenGL();
- cont = new Container(
- new Vertex[] { new Vertex(0.0f, 0.5f, 0.0f),
- new Vertex(-0.5f, -0.5f, 0.0f),
- new Vertex(0.5f, -0.5f, 0.0f) }, new byte[] { 0, 1, 2 });
- while (!Display.isCloseRequested()) {
- this.loopCycle();
- Display.sync(60);
- Display.update();
- }
- cont.destroyResources();
- Display.destroy();
- }
- public void setupOpenGL() {
- try {
- PixelFormat pixelFormat = new PixelFormat();
- ContextAttribs contextAtrributes = new ContextAttribs(3, 0)
- .withForwardCompatible(true);
- Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
- Display.setTitle(WINDOW_TITLE);
- Display.create(pixelFormat, contextAtrributes);
- GL11.glViewport(0, 0, WIDTH, HEIGHT);
- } catch (LWJGLException e) {
- e.printStackTrace();
- System.exit(-1);
- }
- GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f);
- GL11.glViewport(0, 0, WIDTH, HEIGHT);
- }
- public void loopCycle() {
- GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
- while (Keyboard.next()) {
- if (Keyboard.getEventKeyState()) {
- if (Keyboard.getEventKey() == Keyboard.KEY_A) {
- cont.destroyResources();
- cont = new Container(new Vertex[] {
- new Vertex(0.0f, 0.5f, 0.0f),
- new Vertex(-0.5f, -0.5f, 0.0f),
- new Vertex(0.5f, -0.5f, 0.0f) }, new byte[] { 0, 1,
- 2 });
- } else if (Keyboard.getEventKey() == Keyboard.KEY_S) {
- cont.destroyResources();
- cont = new Container(
- new Vertex[] {
- new Vertex(0.0f, 0.5f, 0.0f).setRGB(1,
- 0.5f, 0.2f),
- new Vertex(-0.5f, -0.5f, 0.0f).setRGB(1,
- 0.5f, 0.2f),
- new Vertex(0.5f, -0.5f, 0.0f).setRGB(1,
- 0.5f, 0.2f) },
- new byte[] { 0, 1, 2 });
- } else if (Keyboard.getEventKey() == Keyboard.KEY_D) {
- cont.setVertices(new Vertex[] {
- new Vertex(0.0f, 0.5f, 0.0f).setRGB(1, 0.5f, 0.2f),
- new Vertex(-0.5f, -0.5f, 0.0f)
- .setRGB(0.5f, 1, 0.2f),
- new Vertex(0.5f, -0.5f, 0.0f).setRGB(0.2f, 0.5f, 1) });
- cont.setIndices(new byte[] { 0, 1, 2 });
- cont.updateResources();
- } else if (Keyboard.getEventKey() == Keyboard.KEY_C) {
- System.gc();
- }
- }
- }
- cont.render();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement