java – LWJGL problems with linux

I try to learn lwjgl a bit, but stuggle with the basics. I installed it about 2-3 weeks ago and it worked…at least partly the first 8 chapters from “lwjglbook” project from git were running and now I can’t even start an hello world with lwjgl window.

Have someone an idea what the problem is?

My System: Linux Mint, Nvidia 2060 with 510 drivers glxgears and other graphic benchmarks works (I’m not an Linux expert, switched a few months ago) In the IntelliJ I got this:

Hello LWJGL 3.3.1 build 7!
[LWJGL] GLFW_API_UNAVAILABLE error
   Description : GLX: No GLXFBConfigs returned
   Stacktrace  :
       org.lwjgl.glfw.GLFW.nglfwCreateWindow(GLFW.java:2024)
       org.lwjgl.glfw.GLFW.glfwCreateWindow(GLFW.java:2197)
       HelloWorld.init(HelloWorld.java:49)
       HelloWorld.run(HelloWorld.java:22)
       HelloWorld.main(HelloWorld.java:112)
[LWJGL] GLFW_FORMAT_UNAVAILABLE error
   Description : GLX: Failed to find a suitable GLXFBConfig
   Stacktrace  :
       org.lwjgl.glfw.GLFW.nglfwCreateWindow(GLFW.java:2024)
       org.lwjgl.glfw.GLFW.glfwCreateWindow(GLFW.java:2197)
       HelloWorld.init(HelloWorld.java:49)
       HelloWorld.run(HelloWorld.java:22)
       HelloWorld.main(HelloWorld.java:112)
Exception in thread "main" java.lang.RuntimeException: Failed to create the GLFW window
   at HelloWorld.init(HelloWorld.java:51)
   at HelloWorld.run(HelloWorld.java:22)
   at HelloWorld.main(HelloWorld.java:112)

Process finished with exit code 1

pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>Lwjgltraining1</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>11</maven.compiler.source>
        <maven.compiler.target>11</maven.compiler.target>
    </properties>


    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.lwjgl</groupId>
                <artifactId>lwjgl-bom</artifactId>
                <version>3.3.1</version>
                <scope>import</scope>
                <type>pom</type>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-assimp</artifactId>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-glfw</artifactId>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-openal</artifactId>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-opengl</artifactId>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-stb</artifactId>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl</artifactId>
            <classifier>natives-linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-assimp</artifactId>
            <classifier>natives-linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-glfw</artifactId>
            <classifier>natives-linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-openal</artifactId>
            <classifier>natives-linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-opengl</artifactId>
            <classifier>natives-linux</classifier>
        </dependency>
        <dependency>
            <groupId>org.lwjgl</groupId>
            <artifactId>lwjgl-stb</artifactId>
            <classifier>natives-linux</classifier>
        </dependency>
    </dependencies>


</project>

code:

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 HelloWorld {

    // The window handle
    private long window;

    public void run() {
        System.out.println("Hello LWJGL " + Version.getVersion() + "!");

        init();
        loop();

        // Free the window callbacks and destroy the window
        glfwFreeCallbacks(window);
        glfwDestroyWindow(window);

        // Terminate GLFW and free the error callback
        glfwTerminate();
        glfwSetErrorCallback(null).free();
    }

    private void init() {
        // Setup an error callback. The default implementation
        // will print the error message in System.err.
        GLFWErrorCallback.createPrint(System.err).set();

        // Initialize GLFW. Most GLFW functions will not work before doing this.
        if ( !glfwInit() )
            throw new IllegalStateException("Unable to initialize GLFW");

        // Configure GLFW
        glfwDefaultWindowHints(); // optional, the current window hints are already the default
        glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE); // the window will stay hidden after creation
        glfwWindowHint(GLFW_RESIZABLE, GLFW_TRUE); // the window will be resizable

        // Create the window
        window = glfwCreateWindow(300, 300, "Hello World!", NULL, NULL);
        if ( window == NULL )
            throw new RuntimeException("Failed to create the GLFW window");

        // Setup a key callback. It will be called every time a key is pressed, repeated or released.
        glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
            if ( key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE )
                glfwSetWindowShouldClose(window, true); // We will detect this in the rendering loop
        });

        // Get the thread stack and push a new frame
        try ( MemoryStack stack = stackPush() ) {
            IntBuffer pWidth = stack.mallocInt(1); // int*
            IntBuffer pHeight = stack.mallocInt(1); // int*

            // Get the window size passed to glfwCreateWindow
            glfwGetWindowSize(window, pWidth, pHeight);

            // Get the resolution of the primary monitor
            GLFWVidMode vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());

            // Center the window
            glfwSetWindowPos(
                    window,
                    (vidmode.width() - pWidth.get(0)) / 2,
                    (vidmode.height() - pHeight.get(0)) / 2
            );
        } // the stack frame is popped automatically

        // Make the OpenGL context current
        glfwMakeContextCurrent(window);
        // Enable v-sync
        glfwSwapInterval(1);

        // Make the window visible
        glfwShowWindow(window);
    }

    private void loop() {
        // This line is critical for LWJGL's interoperation with GLFW's
        // OpenGL context, or any context that is managed externally.
        // LWJGL detects the context that is current in the current thread,
        // creates the GLCapabilities instance and makes the OpenGL
        // bindings available for use.
        GL.createCapabilities();

        // Set the clear color
        glClearColor(1.0f, 0.0f, 0.0f, 0.0f);

        // Run the rendering loop until the user has attempted to close
        // the window or has pressed the ESCAPE key.
        while ( !glfwWindowShouldClose(window) ) {
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear the framebuffer

            glfwSwapBuffers(window); // swap the color buffers

            // Poll for window events. The key callback above will only be
            // invoked during this call.
            glfwPollEvents();
        }
    }

    public static void main(String[] args) {
        new HelloWorld().run();
    }

}

edit: it seems something is missing

{Integer@1165} 65537 -> "GLFW_NOT_INITIALIZED"
{Integer@1167} 65539 -> "GLFW_INVALID_ENUM"
{Integer@1169} 65538 -> "GLFW_NO_CURRENT_CONTEXT"
{Integer@1171} 65541 -> "GLFW_OUT_OF_MEMORY"
{Integer@1173} 65540 -> "GLFW_INVALID_VALUE"
{Integer@1175} 65543 -> "GLFW_VERSION_UNAVAILABLE"
{Integer@1177} 65542 -> "GLFW_API_UNAVAILABLE"
{Integer@1179} 65545 -> "GLFW_FORMAT_UNAVAILABLE"
{Integer@1181} 65544 -> "GLFW_PLATFORM_ERROR"
{Integer@1183} 65547 -> "GLFW_CURSOR_UNAVAILABLE"
{Integer@1185} 65546 -> "GLFW_NO_WINDOW_CONTEXT"
{Integer@1187} 65549 -> "GLFW_FEATURE_UNIMPLEMENTED"
{Integer@1189} 65548 -> "GLFW_FEATURE_UNAVAILABLE"
{Integer@1191} 65550 -> "GLFW_PLATFORM_UNAVAILABLE"

Leave a Comment