Advertisement
Guest User

Main Class LWJGL Project

a guest
Oct 31st, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.64 KB | None | 0 0
  1. package se.wouix.voxel;
  2.  
  3. import org.lwjgl.*;
  4. import org.lwjgl.opengl.*;
  5. import org.lwjgl.util.glu.GLU;
  6.  
  7. import se.wouix.voxel.gamestatemanager.GameStateManager;
  8.  
  9. public class VoxelEngine implements Runnable {
  10.    
  11.     public static int HEIGHT = 800;
  12.     public static int WIDTH = 900;
  13.    
  14.     public static double UPS = 60.0;
  15.    
  16.     public static final DisplayMode DISPLAY_MODE = new DisplayMode(WIDTH, HEIGHT);
  17.     public static final String TITLE = "Voxel Tech Test";
  18.    
  19.     public void init() throws LWJGLException {
  20.         Display.setDisplayMode(DISPLAY_MODE);
  21.         Display.setTitle(TITLE);
  22.         Display.setResizable(true);
  23.         Display.create();
  24.        
  25.        
  26.         GL11.glClearColor(0.1f, 0.4f, 0.9f, 1.0f);
  27.        
  28.         GL11.glEnable(GL11.GL_DEPTH_TEST);
  29.         GL11.glEnable(GL11.GL_COLOR_MATERIAL);
  30.        
  31.         GL11.glMatrixMode(GL11.GL_PROJECTION);
  32.         GLU.gluPerspective(45f, DISPLAY_MODE.getWidth()/DISPLAY_MODE.getHeight(), 0.1f, 1000f);
  33.        
  34.         GL11.glMatrixMode(GL11.GL_MODELVIEW);
  35.     }
  36.    
  37.     public void run() {
  38.         try {
  39.             init();
  40.         } catch (LWJGLException e) {
  41.             System.err.println("LWJGL Failed to load");
  42.         }
  43.        
  44.         GameStateManager gsm = new GameStateManager();
  45.         Timer timer = new Timer(UPS);
  46.        
  47.         while (!Display.isCloseRequested()) {
  48.             timer.updateTimer();
  49.            
  50.             while (timer.rightTime()) {
  51.                 gsm.update();
  52.             }
  53.             Display.update();
  54.            
  55.             {
  56.                 GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
  57.                 GL11.glLoadIdentity();
  58.                
  59.                 GL11.glPushMatrix();
  60.                 {
  61.                     gsm.render();
  62.                 }
  63.                 GL11.glPopMatrix();
  64.             }
  65.            
  66.             timer.afterSecond();
  67.         }
  68.     }
  69.    
  70.     public static void main(String[] args) {
  71.         new Thread(new VoxelEngine()).start();
  72.     }
  73.    
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement