lwjgl window 打不开

Lwjgl window not opening

所以我尝试了 lwjgl,但我遇到了问题,当我尝试创建一个 window 我得到一个错误,我不知道为什么。

我曾尝试将 java 版本从 java 16 降低到 14,但这没有用。

主要Class:

package ca.immanuel.flappy;


import org.lwjgl.glfw.GLFWVidMode;

import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.GL_TRUE;
import static org.lwjgl.system.MemoryUtil.NULL;


public class Main implements Runnable {

    private int width = 1280;
    private int height = 720;

    private Thread thread;
    private boolean running = false;

    /*
        LWJGL cant use the GLFWwindow struct because structs don't exist in java
        so we instead use an ID system in Java that's why we use a long.
    */
    private long window;

    public void start() {
        running = true;
        thread = new Thread(this, "Game");
        thread.start();
    }

    private void init() {
        if (!glfwInit()){
            System.out.println("GLFW failed to init!");
            System.exit(-1);
        }

        glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
        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);
        glfwCreateWindow(width, height, "Flappy Bird", NULL, NULL);
        if (window == NULL) {
            System.out.println("Could not create window");
            System.exit(-1);
        }

        GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
        glfwSetWindowPos(window, (vidmode.width() - width) /2, (vidmode.height() - height) /2);
        glfwMakeContextCurrent(window);
        glfwShowWindow(window);
    }

    public void run() {
        init();
        while(running) {
            update();
            render();

            if (glfwWindowShouldClose(window) == true){
                running = false;
            }
        }
    }

    private void update() {
        glfwPollEvents();
    }

    private void render() {
        glfwSwapBuffers(window);
    }

    public static void main(String[] args) {
        new Main().start();
    }
}

当我 运行 我的主要 class 我得到这个错误(在 java jdk 16):

Task :Main.main() FAILED Could not create window

任务“:Main.main()”执行失败。

Process 'command 'C:/Program Files/Java/jdk-16/bin/java.exe'' finished with non-zero exit value -1

我尝试 运行 将其与信息结合起来,这是我的输出:

Task :Main.main() FAILED Caching disabled for task ':Main.main()' because: Build cache is disabled Task ':Main.main()' is not up-to-date because: Task has not declared any outputs despite executing actions. Starting process 'command 'C:/Program Files/Java/jdk-16/bin/java.exe''. Working directory: C:\Users\imman\Documents\FlappyBird Command: C:/Program Files/Java/jdk-16/bin/java.exe -Dfile.encoding=windows-1252 -Duser.country=CA -Duser.language=en -Duser.variant -cp C:\Users\imman\Documents\FlappyBird\build\classes\java\main;C:\Users\imman\Documents\FlappyBird\build\classes\groovy\main;C:\Users\imman\Documents\FlappyBird\build\resources\main;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-bgfx.2.33883c4040fa8df47244dffa1d42c96ce2143de\lwjgl-bgfx-3.2.3.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-bgfx.2.3\f589da97dd3cfa96f42c8c812a0a028cf28223b8\lwjgl-bgfx-3.2.3-natives-windows.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-glfw.2.3e520d5c290c8b012545a8d34fa5db5ab051ea53\lwjgl-glfw-3.2.3.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-glfw.2.3\b4d8a3477cdc2edcf7a5f1e822926be846223f54\lwjgl-glfw-3.2.3-natives-windows.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-nanovg.2.38be4a13691d1cd276fa852326e9e837d65204e\lwjgl-nanovg-3.2.3.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-nanovg.2.3fbe5c2849bcf182ba3c6c09828f032a64cd47ec\lwjgl-nanovg-3.2.3-natives-windows.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-nuklear.2.3bfab23e975201bf3cb81287be6034adec64a86\lwjgl-nuklear-3.2.3.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-nuklear.2.3\ccb63f09670e43e58969b567ef42e02275be555a\lwjgl-nuklear-3.2.3-natives-windows.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-openal.2.36742e805803ab9eab8e343f0fb31a3d263903c\lwjgl-openal-3.2.3.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-openal.2.3\ec898e8ce11b5886f4f532a1536283ef2817758d\lwjgl-openal-3.2.3-natives-windows.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-opengl.2.3\bdd534a323d0c8f54969b95e424b6ac8984f7d6e\lwjgl-opengl-3.2.3.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-opengl.2.3\e81cfc73ec8708e5e791ed770e4ec3edfc1bbab1\lwjgl-opengl-3.2.3-natives-windows.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-par.2.3d96fe3a3345f4c18ca0e682de41b20ec64b70c\lwjgl-par-3.2.3.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-par.2.3\b60677b2948f930736aa2bff952fe8380bfe9fbe\lwjgl-par-3.2.3-natives-windows.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-stb.2.3eccaa4fa86fc815f2e17946a392fb5fdcc286a\lwjgl-stb-3.2.3.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl-stb.2.37b21ec286f0ba3dcedb56a3bd275e6a9345be9\lwjgl-stb-3.2.3-natives-windows.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl.2.3a59ba0fe8d474ec9dbe0d5db40d2cfe59c4c08\lwjgl-3.2.3.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.lwjgl\lwjgl.2.3f32cd35349684745951e04388e8e00d681cdcd\lwjgl-3.2.3-natives-windows.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-ant.0.5\c41c989d5138e9ac48efb1d77e7f271699d10f17\groovy-ant-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-astbuilder.0.5\ab712931e02cb8876d9e39567283a43583ddef20\groovy-astbuilder-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-cli-picocli.0.5\fe73f204778dcb438bb810ec78fd3fc1fe8e5709\groovy-cli-picocli-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-groovysh.0.5b27062568c6b2efb9dd1a2803c0d22bed182ea\groovy-groovysh-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-console.0.5\d0e7aec0100a12600e3e1bb33d9140eff52753fc\groovy-console-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-datetime.0.5\c47535a64ceab4d93227169cb97acab15dfa575a\groovy-datetime-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-groovydoc.0.5\ce4ce5eedd7d18c14433989d777504150f761472\groovy-groovydoc-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-docgenerator.0.5f7ba0ef7a1b9fd0f5fd5550ee31bdb09d565505\groovy-docgenerator-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-jmx.0.5bae59fafaea99a031be9ea4d1af76e4347d62ea\groovy-jmx-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-json.0.5c71dad1aaa890d0012fc72640c1b54263a0de1b\groovy-json-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-jsr223.0.5\cd226c46e662e916d669b6be9467d3b8c591e5d\groovy-jsr223-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-macro.0.56cd0b1654415b6fe24c23dfa0c4de5be9d6ed0\groovy-macro-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-nio.0.55826095f801716e67b1607bb5ad94deb8e4cc9\groovy-nio-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-servlet.0.5\ad3615cd34cd71e8287934140d5e1e4509cbca82\groovy-servlet-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-sql.0.5\c1b21c52f4289083176e11cdeba8c54b3354945e\groovy-sql-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-swing.0.5e204d3ab7dd307cee9cd80d0fe607e0c43a6c5\groovy-swing-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-templates.0.5\df1b1d2f06b7950c7d356983f6edaa99e6fff892\groovy-templates-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-test.0.5a6c5a4a67cbadd2e596296e738dfbb8509e9024\groovy-test-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-test-junit5.0.5\b04895ecd3902448db8da483f087d7ec93894c3e\groovy-test-junit5-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-testng.0.5\a48a9b291fd571adc8a2161a6781ddc121daa48c\groovy-testng-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy-xml.0.5\e2d01a89405dbb5c3a24d0b7db890cefb8d57b2b\groovy-xml-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.codehaus.groovy\groovy.0.55f7c5e0e30e5cf2d24f4efe661e4bfded2dfa2\groovy-3.0.5.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.apache.ant\ant-junit.10.8\f75d2cbe7f63db600fc34e23aa447c27095056cf\ant-junit-1.10.8.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.apache.ant\ant.10.8\ae148abb0532b685c5eeb22fdec9d124e89be5de\ant-1.10.8.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.apache.ant\ant-launcher.10.8ca8688d2dad5694237576db782b37279989614d\ant-launcher-1.10.8.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.apache.ant\ant-antlr.10.8d728985e3b6a71b80d10db0d574a60b496590a1\ant-antlr-1.10.8.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\info.picocli\picocli.4.0\c3e3741e126f70c10bfff50953c42827a57901c1\picocli-4.4.0.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\com.thoughtworks.qdox\qdox.12.1\f7122f6ab1f64bdf9f5970b0e89bfb355e036897\qdox-1.12.1.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\com.github.javaparser\javaparser-core.16.10e5d7118e50d544418a96873d6322c4b1d5527\javaparser-core-3.16.1.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\jline\jline.14.6\c3aeac59c022bdc497c8c48ed86fa50450e4896a\jline-2.14.6.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\junit\junit.13\e49ccba652b735c93bd6e6f59760d8254cf597dd\junit-4.13.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.junit.platform\junit-platform-launcher.6.2\d866de2950859ca1c7996351d7b3d97428083cd0\junit-platform-launcher-1.6.2.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.junit.platform\junit-platform-engine.6.252cad2579e20c2b224602fe846fc660fb35805\junit-platform-engine-1.6.2.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.junit.platform\junit-platform-commons.6.244a14b329e76b5fe487628b50fb5eab6ba7d26\junit-platform-commons-1.6.2.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.junit.jupiter\junit-jupiter-engine.6.2\c0833bd6de29dd77f8d071025b97b8b434308cd3\junit-jupiter-engine-5.6.2.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.junit.jupiter\junit-jupiter-api.6.2\c9ba885abfe975cda123bf6f8f0a69a1b46956d0\junit-jupiter-api-5.6.2.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.testng\testng.1.0\b0bcea778fb2899aeb4014c558babea8833d180a\testng-7.1.0.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.hamcrest\hamcrest-core.3a25dc3219429f0e5d060061f71acb49bf010a0\hamcrest-core-1.3.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\org.opentest4j\opentest4j.2.0c11eb91f9b6d8e200631d46e20a7f407f2a046\opentest4j-1.2.0.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\com.beust\jcommander.7275e521c1e11d6563d4f25a07ce124ccf8cd171\jcommander-1.72.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\com.google.inject\guice.1.0\faf9ee8ac09eafd1128091426dd367a8c0085d55\guice-4.1.0-no_aop.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\javax.inject\javax.inject75da39a7040257bd51d21a231b76c915872d38\javax.inject-1.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\aopalliance\aopalliance.05ba8b489512805ac13a8f9ea77a1ca5ebe3e8\aopalliance-1.0.jar;C:\Users\imman.gradle\caches\modules-2\files-2.1\com.google.guava\guava.0ce200f6b23222af3d8abb6b6459e6c44f4bb0e9\guava-19.0.jar ca.immanuel.flappy.Main Successfully started process 'command 'C:/Program Files/Java/jdk-16/bin/java.exe'' Could not create window :Main.main() (Thread[Execution worker for ':',5,main]) completed. Took 0.784 secs.

任务“:Main.main()”执行失败。

Process 'command 'C:/Program Files/Java/jdk-16/bin/java.exe'' finished with non-zero exit value -1

好的所以问题很简单我从来没有改变 windows 值

在 long window 被设置为空之前

但我发现我必须将它设置为等于 glfwCreateWindow:

之前:

glfwCreateWindow(width, height, "Flappy Bird", NULL, NULL);

之后:

window = glfwCreateWindow(width, height, "Flappy Bird", NULL, NULL);