Skip to content
Advertisement

Lwjgl window not opening

So I trying out lwjgl but I’m having a problem, when I try to create a window I get an error I just can’t figure out why.

I have tried to lower my java version from java 16 to 14 but that didn’t work.

Main 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();
    }
}

when I run my main class I get this error (on java jdk 16):

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

Execution failed for task ‘:Main.main()’.

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

  • Try: Run with –stacktrace option to get the stack trace. Run with –info or –debug option to get more log output. Run with –scan to get full insights.

I tried running it with info and this is my output:

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:UsersimmanDocumentsFlappyBird Command: C:/Program Files/Java/jdk-16/bin/java.exe -Dfile.encoding=windows-1252 -Duser.country=CA -Duser.language=en -Duser.variant -cp C:UsersimmanDocumentsFlappyBirdbuildclassesjavamain;C:UsersimmanDocumentsFlappyBirdbuildclassesgroovymain;C:UsersimmanDocumentsFlappyBirdbuildresourcesmain;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-bgfx3.2.3433883c4040fa8df47244dffa1d42c96ce2143delwjgl-bgfx-3.2.3.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-bgfx3.2.3f589da97dd3cfa96f42c8c812a0a028cf28223b8lwjgl-bgfx-3.2.3-natives-windows.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-glfw3.2.35e520d5c290c8b012545a8d34fa5db5ab051ea53lwjgl-glfw-3.2.3.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-glfw3.2.3b4d8a3477cdc2edcf7a5f1e822926be846223f54lwjgl-glfw-3.2.3-natives-windows.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-nanovg3.2.3718be4a13691d1cd276fa852326e9e837d65204elwjgl-nanovg-3.2.3.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-nanovg3.2.32fbe5c2849bcf182ba3c6c09828f032a64cd47eclwjgl-nanovg-3.2.3-natives-windows.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-nuklear3.2.345bfab23e975201bf3cb81287be6034adec64a86lwjgl-nuklear-3.2.3.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-nuklear3.2.3ccb63f09670e43e58969b567ef42e02275be555alwjgl-nuklear-3.2.3-natives-windows.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-openal3.2.3106742e805803ab9eab8e343f0fb31a3d263903clwjgl-openal-3.2.3.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-openal3.2.3ec898e8ce11b5886f4f532a1536283ef2817758dlwjgl-openal-3.2.3-natives-windows.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-opengl3.2.3bdd534a323d0c8f54969b95e424b6ac8984f7d6elwjgl-opengl-3.2.3.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-opengl3.2.3e81cfc73ec8708e5e791ed770e4ec3edfc1bbab1lwjgl-opengl-3.2.3-natives-windows.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-par3.2.392d96fe3a3345f4c18ca0e682de41b20ec64b70clwjgl-par-3.2.3.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-par3.2.3b60677b2948f930736aa2bff952fe8380bfe9fbelwjgl-par-3.2.3-natives-windows.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-stb3.2.340eccaa4fa86fc815f2e17946a392fb5fdcc286alwjgl-stb-3.2.3.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl-stb3.2.3817b21ec286f0ba3dcedb56a3bd275e6a9345be9lwjgl-stb-3.2.3-natives-windows.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl3.2.317a59ba0fe8d474ec9dbe0d5db40d2cfe59c4c08lwjgl-3.2.3.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.lwjgllwjgl3.2.327f32cd35349684745951e04388e8e00d681cdcdlwjgl-3.2.3-natives-windows.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-ant3.0.5c41c989d5138e9ac48efb1d77e7f271699d10f17groovy-ant-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-astbuilder3.0.5ab712931e02cb8876d9e39567283a43583ddef20groovy-astbuilder-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-cli-picocli3.0.5fe73f204778dcb438bb810ec78fd3fc1fe8e5709groovy-cli-picocli-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-groovysh3.0.580b27062568c6b2efb9dd1a2803c0d22bed182eagroovy-groovysh-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-console3.0.5d0e7aec0100a12600e3e1bb33d9140eff52753fcgroovy-console-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-datetime3.0.5c47535a64ceab4d93227169cb97acab15dfa575agroovy-datetime-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-groovydoc3.0.5ce4ce5eedd7d18c14433989d777504150f761472groovy-groovydoc-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-docgenerator3.0.57f7ba0ef7a1b9fd0f5fd5550ee31bdb09d565505groovy-docgenerator-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-jmx3.0.55bae59fafaea99a031be9ea4d1af76e4347d62eagroovy-jmx-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-json3.0.53c71dad1aaa890d0012fc72640c1b54263a0de1bgroovy-json-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-jsr2233.0.5cd226c46e662e916d669b6be9467d3b8c591e5dgroovy-jsr223-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-macro3.0.5106cd0b1654415b6fe24c23dfa0c4de5be9d6ed0groovy-macro-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-nio3.0.5225826095f801716e67b1607bb5ad94deb8e4cc9groovy-nio-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-servlet3.0.5ad3615cd34cd71e8287934140d5e1e4509cbca82groovy-servlet-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-sql3.0.5c1b21c52f4289083176e11cdeba8c54b3354945egroovy-sql-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-swing3.0.557e204d3ab7dd307cee9cd80d0fe607e0c43a6c5groovy-swing-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-templates3.0.5df1b1d2f06b7950c7d356983f6edaa99e6fff892groovy-templates-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-test3.0.58a6c5a4a67cbadd2e596296e738dfbb8509e9024groovy-test-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-test-junit53.0.5b04895ecd3902448db8da483f087d7ec93894c3egroovy-test-junit5-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-testng3.0.5a48a9b291fd571adc8a2161a6781ddc121daa48cgroovy-testng-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy-xml3.0.5e2d01a89405dbb5c3a24d0b7db890cefb8d57b2bgroovy-xml-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.codehaus.groovygroovy3.0.5545f7c5e0e30e5cf2d24f4efe661e4bfded2dfa2groovy-3.0.5.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.apache.antant-junit1.10.8f75d2cbe7f63db600fc34e23aa447c27095056cfant-junit-1.10.8.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.apache.antant1.10.8ae148abb0532b685c5eeb22fdec9d124e89be5deant-1.10.8.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.apache.antant-launcher1.10.82ca8688d2dad5694237576db782b37279989614dant-launcher-1.10.8.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.apache.antant-antlr1.10.83d728985e3b6a71b80d10db0d574a60b496590a1ant-antlr-1.10.8.jar;C:Usersimman.gradlecachesmodules-2files-2.1info.picoclipicocli4.4.0c3e3741e126f70c10bfff50953c42827a57901c1picocli-4.4.0.jar;C:Usersimman.gradlecachesmodules-2files-2.1com.thoughtworks.qdoxqdox1.12.1f7122f6ab1f64bdf9f5970b0e89bfb355e036897qdox-1.12.1.jar;C:Usersimman.gradlecachesmodules-2files-2.1com.github.javaparserjavaparser-core3.16.1440e5d7118e50d544418a96873d6322c4b1d5527javaparser-core-3.16.1.jar;C:Usersimman.gradlecachesmodules-2files-2.1jlinejline2.14.6c3aeac59c022bdc497c8c48ed86fa50450e4896ajline-2.14.6.jar;C:Usersimman.gradlecachesmodules-2files-2.1junitjunit4.13e49ccba652b735c93bd6e6f59760d8254cf597ddjunit-4.13.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.junit.platformjunit-platform-launcher1.6.2d866de2950859ca1c7996351d7b3d97428083cd0junit-platform-launcher-1.6.2.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.junit.platformjunit-platform-engine1.6.21752cad2579e20c2b224602fe846fc660fb35805junit-platform-engine-1.6.2.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.junit.platformjunit-platform-commons1.6.27644a14b329e76b5fe487628b50fb5eab6ba7d26junit-platform-commons-1.6.2.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.junit.jupiterjunit-jupiter-engine5.6.2c0833bd6de29dd77f8d071025b97b8b434308cd3junit-jupiter-engine-5.6.2.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.junit.jupiterjunit-jupiter-api5.6.2c9ba885abfe975cda123bf6f8f0a69a1b46956d0junit-jupiter-api-5.6.2.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.testngtestng7.1.0b0bcea778fb2899aeb4014c558babea8833d180atestng-7.1.0.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.hamcresthamcrest-core1.342a25dc3219429f0e5d060061f71acb49bf010a0hamcrest-core-1.3.jar;C:Usersimman.gradlecachesmodules-2files-2.1org.opentest4jopentest4j1.2.028c11eb91f9b6d8e200631d46e20a7f407f2a046opentest4j-1.2.0.jar;C:Usersimman.gradlecachesmodules-2files-2.1com.beustjcommander1.726375e521c1e11d6563d4f25a07ce124ccf8cd171jcommander-1.72.jar;C:Usersimman.gradlecachesmodules-2files-2.1com.google.injectguice4.1.0faf9ee8ac09eafd1128091426dd367a8c0085d55guice-4.1.0-no_aop.jar;C:Usersimman.gradlecachesmodules-2files-2.1javax.injectjavax.inject16975da39a7040257bd51d21a231b76c915872d38javax.inject-1.jar;C:Usersimman.gradlecachesmodules-2files-2.1aopallianceaopalliance1.0235ba8b489512805ac13a8f9ea77a1ca5ebe3e8aopalliance-1.0.jar;C:Usersimman.gradlecachesmodules-2files-2.1com.google.guavaguava19.06ce200f6b23222af3d8abb6b6459e6c44f4bb0e9guava-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.

Execution failed for task ‘:Main.main()’.

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

  • Try: Run with –stacktrace option to get the stack trace. Run with –debug option to get more log output. Run with –scan to get full insights.

Advertisement

Answer

Ok so the problem was very simple I never changed the windows value

before the long window was set to nothing

but I figured out that I had to set it equal to glfwCreateWindow:

before:

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

after:

window = glfwCreateWindow(width, height, "Flappy Bird", NULL, NULL);
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement