Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.voxel.engine.core;
- import com.voxel.engine.core.Block.Block;
- import com.voxel.engine.core.Camera.FPCameraController;
- import com.voxel.engine.core.Chunk.ChunkManager;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.input.Keyboard;
- import org.lwjgl.opengl.*;
- import org.lwjgl.util.glu.GLU;
- import java.util.Random;
- import static org.lwjgl.opengl.GL11.*;
- /**
- * Created with IntelliJ IDEA.
- * User: Toby's PC
- * Date: 06/01/14
- * Time: 15:47
- */
- public class Core {
- public static final int WORLD_WIDTH = 8;
- public static final int WORLD_HEIGHT = 1;
- public static final int BLOCK_WIDTH = 16;
- public static final int BLOCK_HEIGHT = 16;
- private Cube cube = new Cube();
- private Block.BlockType blockType = Block.BlockType.BLOCK_TYPE_STONE;
- FPCameraController camera = FPCameraController.getInstance();
- public static final int SCREEN_WIDTH = 640;
- public static final int SCREEN_HEIGHT = 480;
- public static final String TITLE = "Voxel Engine V0.01";
- private float playerX, playerY, playerZ;
- /**
- * Method that is run at the start
- */
- public void start(){
- try{
- createWindow(SCREEN_WIDTH, SCREEN_HEIGHT, TITLE);
- PixelFormat pixelFormat = new PixelFormat();
- ContextAttribs contextAttribs = new ContextAttribs(3, 0);
- Display.create(pixelFormat, contextAttribs);
- glViewport(0, 0, Display.getDisplayMode().getWidth(), Display.getDisplayMode().getHeight());
- if(GLContext.getCapabilities().OpenGL21){
- System.out.println("OpenGL21 Supported");
- }
- Random random = new Random();
- for(int x = 0;x < 16;x++){
- for (int z = 0;z < 16;z++){
- ChunkManager.getInstance().addChunk(ChunkManager.ChunkType.CHUNK_TYPE_RANDOM, x, 0, z);
- }
- }
- initGL();
- run();
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- /**
- * Creates our window based on values given
- *
- * @param width, Width of our screen
- * @param height, Height of our screen
- * @param title, The title of the game
- */
- public void createWindow(int width, int height, String title){
- try {
- Display.setFullscreen(false);
- Display.setDisplayMode(new DisplayMode(width, height));
- Display.setTitle(title);
- Display.setVSyncEnabled(true);
- } catch (LWJGLException e) {
- e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
- }
- }
- /**
- * Init all the graphics components
- */
- public void initGL(){
- GL11.glMatrixMode(GL_PROJECTION);
- GL11.glLoadIdentity();
- GLU.gluPerspective(45.0f, (float) Display.getDisplayMode().getWidth() / (float) Display.getDisplayMode().getHeight(), 0.1f, 300.0f);
- GL11.glEnable(GL11.GL_FOG);
- GL11.glTranslatef(0, -1f, 0f);
- GL11.glRotatef(180.0f, 0, 1.0f, 0);
- GL11.glMatrixMode(GL_MODELVIEW);
- GL11.glLoadIdentity();
- GL11.glShadeModel(GL_LINE_SMOOTH);
- GL11.glClearColor(0.1f, 0.5f, 0.7f, 0.0f);
- GL11.glClearDepth(1.0);
- GL11.glEnable(GL_DEPTH_TEST);
- GL11.glDepthFunc(GL11.GL_LEQUAL);
- GL11.glHint(GL11.GL_PERSPECTIVE_CORRECTION_HINT, GL11.GL_NICEST);
- GL11.glCullFace(GL11.GL_BACK);
- GL11.glEnable(GL11.GL_CULL_FACE);
- }
- public void run(){
- float rotateYaw = 1;
- while(!Display.isCloseRequested()){
- try{
- inputManager();
- GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
- GL11.glLoadIdentity();
- GL11.glTranslatef(-30f + playerX, -40f + playerY, -160f + playerZ);
- GL11.glRotatef(45f, 0.4f, 1.0f, 0.1f);
- GL11.glRotatef(45f, 0f, 1.0f, 0f);
- rotateYaw += 1;
- render();
- Display.update();
- Display.sync(60);
- }catch(Exception e){
- e.printStackTrace();
- }
- }
- Display.destroy();
- }
- public void inputManager() {
- if(Keyboard.isKeyDown(Keyboard.KEY_W)){
- playerY--;
- }
- if(Keyboard.isKeyDown(Keyboard.KEY_S)){
- playerY++;
- }
- if(Keyboard.isKeyDown(Keyboard.KEY_A)){
- playerX++;
- }
- if(Keyboard.isKeyDown(Keyboard.KEY_D)){
- playerX--;
- }
- if(Keyboard.isKeyDown(Keyboard.KEY_E)){
- playerZ--;
- }
- if(Keyboard.isKeyDown(Keyboard.KEY_Q)){
- playerZ++;
- }
- }
- public void render(){
- ChunkManager.getInstance().render();
- }
- public static void main(String[] args){
- Core core = new Core();
- core.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement