【问题标题】:LWJGL 3 - GLFW Window crashLWJGL 3 - GLFW 窗口崩溃
【发布时间】:2021-10-17 22:06:35
【问题描述】:

所以,我对 LWJGL 和 GLFW 还是很陌生,我正在学习教程。我在 MacOS Big Sur 11.5.2 上,窗口确实保持打开状态,但立即崩溃并且不显示。有谁知道为什么会这样?教程:click here LWJGL 版本:3.2.2 JDK:JavaSE-1.8

Window.java:

package com.bmc.voxel3d;

import org.lwjgl.glfw.GLFW;
import org.lwjgl.glfw.GLFWVidMode;

public class Window {
    private int width, height;
    private String title;
    private long window;
    
    public Window(int width, int height, String title) {
        this.width = width;
        this.height = height;
        this.title = title;
    }
    
    public void create() {
        if(!GLFW.glfwInit()) {
            System.out.println("ERROR: Didn't initialize GLFW.");
            return;
        }
        
        window = GLFW.glfwCreateWindow(width, height, title, 0, 0);
        
        if(window == 0) {
            System.out.println("ERROR: Could not make window.");
            return;
        }
        
        GLFWVidMode videoMode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
        GLFW.glfwSetWindowPos(window, (videoMode.width() - width) / 2, (videoMode.height() - height / 2));
        GLFW.glfwShowWindow(window);
    }
}

和 Main.java:

package com.bmc.minecraft;

import com.bmc.voxel3d.Window;

public class Main implements Runnable{
    public Thread game;
    public static Window window;
    public static final int WIDTH = 854, HEIGHT = 480;
    
    public void start() {
        game = new Thread(this, "game");
        game.start();
    }
    
    public static void init() {
        System.out.println("Initializing Game!");
        window = new Window(WIDTH, HEIGHT, "Game");
        window.create();
    }
    
    public void run() {
        init();
        while(true) {
            update();
            render();
        }
    }
    
    private void update() {
        System.out.println("Updating Game!");
    }
    
    private void render() {
        System.out.println("Rendering Game!");
    }
    
    public static void main(String[] args){
        new Main().start();
    }
}

另外,我在运行配置中有 -XstartOnFirstThread 日食 2019

【问题讨论】:

    标签: java eclipse lwjgl glfw


    【解决方案1】:

    我假设您的意思是窗口没有响应用户输入。

    解决方案相当简单,你需要在游戏循环中输入!glfwWindowShouldClose(window),而不是true,这将告诉GLFW当按下x按钮时它应该关闭。

    【讨论】:

      猜你喜欢
      • 2016-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多