Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package passage.games;
- import static org.lwjgl.opengl.GL11.*;
- import static org.lwjgl.opengl.GL20.*;
- import java.lang.reflect.Field;
- import org.lwjgl.LWJGLException;
- import org.lwjgl.input.Keyboard;
- import org.lwjgl.input.Mouse;
- import org.lwjgl.opengl.Display;
- import org.lwjgl.opengl.DisplayMode;
- import org.lwjgl.opengl.PixelFormat;
- import org.lwjgl.util.glu.GLU;
- import org.lwjgl.util.vector.Vector3f;
- public class Game {
- public Game() throws LWJGLException {init();}
- public DisplayMode displayMode = null;
- public PixelFormat pixelFormat = null;
- public Camera camera = new Camera();
- public Block block = new Block();
- public Block block2 = new Block();
- public Shader shader;
- public void init() throws LWJGLException{
- displayMode = new DisplayMode(800, 600);
- pixelFormat = new PixelFormat(8, 16, 1, 4);
- resetDisplay();
- updateProjection();
- Keyboard.create();
- Mouse.create();
- glClearColor(0.5f, 0.5f, 0.5f, 1f);
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LEQUAL);
- glClearDepth(1.0f);
- glDisable(GL_CULL_FACE);
- block.init();
- block2.init();
- block2.location = new Vector3f(0, 2, 0);
- shader = new Shader();
- shader.attachVertexShader("assets/box.vert");
- shader.attachFragmentShader("assets/box.frag");
- shader.link();
- while(!Display.isCloseRequested()){
- update();
- render();
- }
- }
- public void render(){
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- if(Display.wasResized()) updateProjection();
- glLoadIdentity();
- camera.translatePosition();
- shader.bind();
- glUniform3f(glGetUniformLocation(shader.programID, "lightLocation"), camera.vector.x, camera.vector.y, 10);
- block.render();
- block2.render();
- shader.unbind();
- Display.update();
- }
- public void update(){
- camera.update();
- block.update();
- block2.update();
- Display.sync(60);
- }
- public void destroy(){
- block.destroy();
- Keyboard.destroy();
- Mouse.destroy();
- Display.destroy();
- }
- public static void main(String[] args) throws LWJGLException{
- new Game();
- }
- public void resetDisplay() throws LWJGLException{
- if(Display.isCreated()) Display.destroy();
- Display.setDisplayMode(displayMode);
- Display.create(pixelFormat);
- }
- public void updateProjection(){
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- GLU.gluPerspective(45, (float)800 / 600, 0.1f, 1000);
- glMatrixMode(GL_MODELVIEW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement