Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.mrpizzacake.futura.core;
- import org.lwjgl.opengl.GLContext;
- import org.lwjgl.system.glfw.ErrorCallback;
- import org.lwjgl.system.glfw.GLFWvidmode;
- import java.nio.ByteBuffer;
- import static org.lwjgl.system.MemoryUtil.*;
- import static org.lwjgl.system.glfw.GLFW.*;
- import static org.lwjgl.opengl.GL11.*;
- public class Window
- {
- private long id;
- private final Game game;
- public final int width;
- public final int height;
- private final CharSequence title;
- private final double aspect;
- public Window(Game g, int w, int h, CharSequence t)
- {
- game = g;
- width = w;
- height = h;
- title = t;
- aspect = (double)width / (double)height;
- game.parent = this;
- if ((id = glfwCreateWindow(width, height, title, NULL, NULL)) == NULL)
- throw new RuntimeException("Window couldn't be created");
- ByteBuffer vidMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
- glfwSetWindowPos(
- id,
- (GLFWvidmode.width(vidMode) - width) / 2,
- (GLFWvidmode.height(vidMode) - height) / 2
- );
- glfwMakeContextCurrent(id);
- GLContext.createFromCurrent();
- glViewport(0, 0, width, height);
- glMatrixMode(GL_PROJECTION);
- glOrtho(0, width, 0, height, -1, 1);
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
- glfwShowWindow(id);
- game.init();
- while ( glfwWindowShouldClose(id) == GL_FALSE ) {
- update();
- render();
- }
- glfwDestroyWindow(id);
- }
- private void update()
- {
- game.update(this);
- }
- private void render()
- {
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glLoadIdentity();
- game.render(this);
- System.out.println(glGetError());
- glfwSwapBuffers(id);
- glfwPollEvents();
- }
- public static void initGLFW()
- {
- glfwSetErrorCallback(ErrorCallback.Util.getDefault());
- if (glfwInit() != GL_TRUE)
- throw new RuntimeException("GLFW couldn't be initialized");
- glfwDefaultWindowHints();
- glfwWindowHint(GLFW_VISIBLE, GL_FALSE);
- glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment