简体   繁体   English

LWJGL 问题与 linux +nvidia 510 驱动程序

[英]LWJGL problems with linux +nvidia 510 driver

I try to learn lwjgl a bit, but stuggle with the basics.我尝试学习一点 lwjgl,但在基础知识上挣扎。 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.我在大约 2-3 周前安装了它并且它起作用了......至少部分来自 git 的“lwjglbook”项目的前 8 章正在运行,现在我什至无法使用 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 few months ago) In the IntelliJ I got this:我的系统:Linux Mint,Nvidia 2060,带有 510 个驱动程序 glxgears 和其他图形基准测试(我不是 Linux 专家,几个月前切换)在 IntelliJ 中我得到了这个:

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: 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"

edit编辑

have maybe an solution:也许有一个解决方案:

sudo apt purge nvidia-* sudo apt autoremove sudo apt autoclean sudo apt purge nvidia-* sudo apt autoremove sudo apt autoclean

三角形 mesa is fallback driver I think mesa 是我认为的后备驱动程序

now I have to test what is working or not, glxgears starts.现在我必须测试什么有效或无效,glxgears 启动。

edit: still not the final solution, performance on games is < 0编辑:仍然不是最终解决方案,游戏性能 < 0

can I kick mesa and keep nvidia 510 driver?我可以踢台面并保留 nvidia 510 驱动程序吗? maybe mesa+nvidia is an issue也许 mesa+nvidia 是个问题

edit2: I have tried nouveau drivers, lwjgl starts but performance is on 30-50%, some games do not even starts edit2:我试过 nouveau 驱动程序,lwjgl 启动但性能在 30-50%,有些游戏甚至不启动

fixed.固定的。 root cause was broken IntelliJ installation via flatpak and not driver issue根本原因是通过 flatpak 破坏了 IntelliJ 安装,而不是驱动程序问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM