quickprojects
Version:
QuickProjects makes it easy to create templates for programming projects without having to use an IDE.
88 lines (63 loc) • 1.81 kB
Plain Text
package mainPackage;
import org.lwjgl.*;
import org.lwjgl.glfw.*;
import org.lwjgl.opengl.*;
import org.lwjgl.system.*;
import java.nio.*;
import static org.lwjgl.glfw.Callbacks.*;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryStack.*;
import static org.lwjgl.system.MemoryUtil.*;
public class Main {
private final int WIDTH = 640, HEIGHT = 480;
private long window;
private InputManager input;
// Initializes the window.
public void init() {
// GLFW Initialization.
if(!glfwInit()) throw new IllegalStateException("Couldn't initialize GLFW.");
// Create the application window.
glfwDefaultWindowHints();
window = glfwCreateWindow(WIDTH, HEIGHT, "Title", NULL, NULL);
if(window == NULL) System.exit(0);
// Handle input.
glfwSetKeyCallback(window, new InputManager());
// Show window.
glfwMakeContextCurrent(window);
glfwShowWindow(window);
}
// Starts the application.
public void start() {
init();
startGameLoop();
glfwFreeCallbacks(window);
glfwDestroyWindow(window);
glfwTerminate();
//glfwSetErrorCallback(null).free();
}
// Starts the game loop.
private void startGameLoop() {
// Clear graphics.
GL.createCapabilities();
glClearColor(1.0f, 1.0f, 1.0f, 1.0f);
// Main loop.
while ( !glfwWindowShouldClose(window) ) {
update();
draw();
}
}
public void update() {
glfwPollEvents();
}
public void draw() {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer
glfwSwapBuffers(window);
// Other graphics stuff.
}
public static void main(String[] args) {
// Necessary for running on MacOS during development.
if(MacRunner.restartJVM()) { return; }
new Main().start();
}
}