Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.smorce.project;
- import static org.lwjgl.glfw.GLFW.*;
- import static org.lwjgl.opengl.GL11.*;
- import static org.lwjgl.system.MemoryUtil.*;
- import org.lwjgl.glfw.GLFWVidMode;
- import me.smorce.project.input.Input;
- public class Game
- {
- public boolean running = false;
- private long window;
- public int windowWidth = 1280;
- public int windowHeight = windowWidth / 16 * 9;
- public void start()
- {
- running = true;
- init();
- while(running)
- {
- update();
- render();
- if(glfwWindowShouldClose(window)) running = false;
- }
- }
- private void init()
- {
- if(!glfwInit())
- {
- System.err.println("GLFW failed to initialize!");
- return;
- }
- glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
- window = glfwCreateWindow(windowWidth, windowHeight, "Game", NULL, NULL);
- if(window == NULL)
- {
- System.err.println("GLFW failed to create the window");
- return;
- }
- GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
- glfwSetWindowPos(window, (videoMode.width() - windowWidth) / 2, (videoMode.height() - windowHeight) / 2);
- glfwSetKeyCallback(window, new Input());
- glfwMakeContextCurrent(window);
- glEnable(GL_DEPTH_TEST);
- System.out.println("OpenGL: " + glGetString(GL_VERSION));
- glfwShowWindow(window);
- glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
- }
- private void update()
- {
- glfwPollEvents();
- if(Input.keys[GLFW_KEY_SPACE])
- {
- System.out.println("SPACE BAR");
- }
- }
- private void render()
- {
- glfwSwapBuffers(window);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment