Guest User

Untitled

a guest
May 31st, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.16 KB | None | 0 0
  1. package net.test;
  2.  
  3. import java.io.File;
  4.  
  5. import org.lwjgl.LWJGLException;
  6. import org.lwjgl.LWJGLUtil;
  7. import org.lwjgl.input.Keyboard;
  8. import org.lwjgl.opengl.Display;
  9. import org.lwjgl.opengl.DisplayMode;
  10. import org.lwjgl.opengl.GL11;
  11. import org.lwjgl.util.glu.GLU;
  12.  
  13. public class Main {
  14.     // Entry point for the application
  15.     public static void main(String[] args) {
  16.         System.setProperty("org.lwjgl.librarypath",
  17.                 new File(new File(System.getProperty("user.dir"), "native"),
  18.                         LWJGLUtil.getPlatformName()).getAbsolutePath());
  19.         new Main();
  20.     }
  21.  
  22.     private final String WINDOW_TITLE = "CubeTest";
  23.     private final int WIDTH = 640;
  24.     private final int HEIGHT = 360;
  25.  
  26.     private Container cont;
  27.  
  28.     public static int superCount;
  29.  
  30.     public Main() {
  31.         this.setupOpenGL();
  32.  
  33.         cont = new Container();
  34.         cont.setVertices(new Vertex[] { new Vertex(0.0f, 0.5f, 0.0f),
  35.                 new Vertex(-0.5f, -0.5f, 0.0f), new Vertex(0.5f, -0.5f, 0.0f) });
  36.         cont.setIndices(new byte[] { 0, 1, 2 });
  37.  
  38.         while (!Display.isCloseRequested()) {
  39.             this.ready3D();
  40.             this.loopCycle();
  41.  
  42.             Display.sync(60);
  43.             Display.update();
  44.         }
  45.  
  46.         cont.destroyResources();
  47.  
  48.         Display.destroy();
  49.     }
  50.  
  51.     public void setupOpenGL() {
  52.         try {
  53.             Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
  54.             Display.setTitle(WINDOW_TITLE);
  55.             Display.create();
  56.         } catch (LWJGLException e) {
  57.             e.printStackTrace();
  58.             System.exit(-1);
  59.         }
  60.  
  61.         GL11.glClearColor(0.4f, 0.6f, 0.9f, 0f);
  62.     }
  63.  
  64.     private void ready3D() {
  65.         GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
  66.  
  67.         GL11.glViewport(0, 0, WIDTH, HEIGHT);
  68.         GL11.glMatrixMode(GL11.GL_PROJECTION);
  69.  
  70.         GL11.glLoadIdentity();
  71.         GLU.gluPerspective(60, (float) WIDTH / HEIGHT, 0.1f, 10.0f);
  72.  
  73.         GL11.glMatrixMode(GL11.GL_MODELVIEW);
  74.         GL11.glLoadIdentity();
  75.     }
  76.  
  77.     public void loopCycle() {
  78.         superCount++;
  79.  
  80.         float sinOff = (float) Math.sin(superCount / 30f) / 2f, cosOff = (float) Math
  81.                 .cos(superCount / 30f) / 2f;
  82.  
  83.         cont.setVertices(new Vertex[] {
  84.                 new Vertex(0.0f, 0.5f, cosOff).setRGB(1, 0.6f, 0.2f),
  85.                 new Vertex(-0.5f, -0.5f, 0.0f), new Vertex(0.5f, -0.5f, 0.0f) });
  86.         cont.setIndices(new byte[] { 0, 1, 2 });
  87.  
  88.         cont.render();
  89.     }
  90. }
Advertisement
Add Comment
Please, Sign In to add comment