skunkworks/com/danitheskunk/skunkworks/GLWindow.java

59 lines
1.4 KiB
Java

package com.danitheskunk.skunkworks;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GL11;
import org.lwjgl.stb.STBRectPack;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.NULL;
public class GLWindow implements IWindow {
private long window;
private boolean shouldClose;
public GLWindow(int width, int height, String title) {
GLFWErrorCallback.createPrint(System.err).set();
if (!glfwInit())
throw new IllegalStateException("Unable to initialize GLFW");
glfwDefaultWindowHints();
window = glfwCreateWindow(width, height, title, NULL, NULL);
if (window == NULL)
throw new RuntimeException("Failed to create GLFW window");
glfwMakeContextCurrent(window);
glfwSwapInterval(1); //vsync
glfwShowWindow(window);
GL.createCapabilities();
shouldClose = false;
System.out.println("Skunkworks window initialised");
System.out.print("Maximum Texture Size: ");
System.out.println(GL11.glGetInteger(GL_MAX_TEXTURE_SIZE));
}
@Override
public boolean shouldClose() {
return shouldClose;
}
@Override
public void tick() {
if(glfwWindowShouldClose(window)) {
shouldClose = true;
return;
}
glClearColor(0.1f, 0.2f, 0.3f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glfwSwapBuffers(window);
glfwPollEvents();
}
}