linux +nvidia 510 驱动程序的 LWJGL 问题
LWJGL problems with linux +nvidia 510 driver
我尝试学习一点 lwjgl,但在基础知识上挣扎。
我大约在 2-3 周前安装了它并且它起作用了……至少部分起作用了
git 的“lwjglbook”项目的前 8 章是 运行,现在我什至无法使用 lwjgl window.
开始一个你好世界
有人知道问题出在哪里吗?
我的系统:LinuxMint,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:
<?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>
代码:
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();
}
}
编辑:
好像少了什么
{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"
编辑
也许有解决办法:
sudo apt purge nvidia-*
须藤易于自动删除
sudo apt autoclean
我认为 mesa 是后备驱动程序
现在我必须测试什么在工作,glxgears 启动。
编辑:仍然不是最终解决方案,游戏性能<0
我可以踢掉台面并保留 nvidia 510 驱动程序吗?也许 mesa+nvidia 是个问题
edit2: 我试过 nouveau 驱动,lwjgl 启动但性能在 30-50%,有些游戏甚至不启动
已修复。
根本原因是通过 flatpak 破坏了 IntelliJ 安装
而不是驱动程序问题
我尝试学习一点 lwjgl,但在基础知识上挣扎。 我大约在 2-3 周前安装了它并且它起作用了……至少部分起作用了 git 的“lwjglbook”项目的前 8 章是 运行,现在我什至无法使用 lwjgl window.
开始一个你好世界有人知道问题出在哪里吗?
我的系统:LinuxMint,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:
<?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>
代码:
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();
}
}
编辑: 好像少了什么
{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"
编辑
也许有解决办法:
sudo apt purge nvidia-* 须藤易于自动删除 sudo apt autoclean
现在我必须测试什么在工作,glxgears 启动。
编辑:仍然不是最终解决方案,游戏性能<0
我可以踢掉台面并保留 nvidia 510 驱动程序吗?也许 mesa+nvidia 是个问题
edit2: 我试过 nouveau 驱动,lwjgl 启动但性能在 30-50%,有些游戏甚至不启动
已修复。 根本原因是通过 flatpak 破坏了 IntelliJ 安装 而不是驱动程序问题