Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.main;
- import org.lwjgl.glfw.GLFWKeyCallback;
- import static org.lwjgl.glfw.GLFW.*;
- import static org.lwjgl.opengl.GL11.*;
- import static org.lwjgl.system.MemoryUtil.*;
- import org.lwjgl.opengl.GLContext;
- public class Main {
- private boolean running;
- private static long windowID;
- GLFWKeyCallback keyCallback;
- public Main() {
- initWindow();
- }
- private static void initWindow() {
- // Inizializza GLFW
- if (glfwInit() != GL_TRUE)
- {
- System.err.println("Error initializing GLFW");
- System.exit(1);
- }
- // Crea la Finestra
- windowID = glfwCreateWindow(1366, 768, "Window", NULL, NULL);
- if (windowID == NULL)
- {
- System.err.println("Error creating a window");
- System.exit(1);
- }
- glfwWindowHint(GLFW_SAMPLES, 4);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
- glfwMakeContextCurrent(windowID);
- GLContext.createFromCurrent();
- glfwSwapInterval(1);
- }
- public void initGame() {
- }
- public void update(float delta) {
- if (glfwGetKey(windowID, GLFW_KEY_UP) == GLFW_PRESS)
- {
- running = false;
- }
- }
- public void render(float delta) {
- }
- public void dispose() {
- }
- public void end() {
- running = false;
- }
- public void start() {
- float now, last, delta;
- last = 0;
- glfwSetKeyCallback(windowID, keyCallback = GLFWKeyCallback(this::glfwKeyCallback));
- // Inizializza il Gioco
- initGame();
- running = true;
- // Loop continuously and render and update
- while (running && glfwWindowShouldClose(windowID) != GL_TRUE)
- {
- // Get the time
- now = (float) glfwGetTime();
- delta = now - last;
- last = now;
- // Update e Render
- update(delta);
- render(delta);
- // Poll the events and swap the buffers
- glfwPollEvents();
- glfwSwapBuffers(windowID);
- }
- // Dispose the game
- dispose();
- // Release the callbacks
- keyCallback.release();
- // Distrugge la Finestra al Termine del Programma
- glfwDestroyWindow(windowID);
- glfwTerminate();
- System.exit(0);
- }
- public void glfwKeyCallback(long window, int key, int scancode, int action, int mods)
- {
- // End on escape
- if (key == GLFW_KEY_ESCAPE && action != GLFW_RELEASE)
- end();
- }
- public static long getWindowID() {
- return windowID;
- }
- public static void main(String[] args) {
- new Main().start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement