gpt4 book ai didi

java - 窗口打开时出错?

转载 作者:太空宇宙 更新时间:2023-11-04 13:52:38 25 4
gpt4 key购买 nike

当我制作一个简单的窗口时,它给了我一个错误,我不知道为什么!我使用的是 Linux Mint 64 位。 (戴尔灵越 1764)

错误如下:

org.lwjgl.LWJGLException: X Error - disp: 0x7f81187c9a20 serial: 93 error: GLXBadFBConfig request_code: 156 minor_code: 34
at org.lwjgl.opengl.LinuxDisplay.globalErrorHandler(LinuxDisplay.java:321)
at org.lwjgl.opengl.LinuxContextImplementation.nCreate(Native Method)
at org.lwjgl.opengl.LinuxContextImplementation.create(LinuxContextImplementation.java:51)
at org.lwjgl.opengl.ContextGL.<init>(ContextGL.java:132)
at org.lwjgl.opengl.Display.create(Display.java:850)
at org.lwjgl.opengl.Display.create(Display.java:797)
at renderEngine.DisplayManager.createDisplay(DisplayManager.java:27)
at engineTester.MainGameLoop.main(MainGameLoop.java:10)

Exception in thread "main" java.lang.IllegalStateException: Cannot determine close requested state of uncreated window
at org.lwjgl.opengl.Display.isCloseRequested(Display.java:549)
at engineTester.MainGameLoop.main(MainGameLoop.java:14)

这是我的代码:

package engineTester;

import org.lwjgl.opengl.Display;

import renderEngine.DisplayManager;

public class MainGameLoop {

public static void main(String[] args) {
DisplayManager.createDisplay();

while(!Display.isCloseRequested()) {
//game logic
//render
DisplayManager.updateDisplay();
}

DisplayManager.closeDisplay();
}

}

然后另一个类是:

package renderEngine;

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.ContextAttribs;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.PixelFormat;
import org.lwjgl.test.applet.OpenGL;

public class DisplayManager {

private static final int WIDTH = 1000;

private static final int HEIGHT = 700;

private static final int FPS_CAP = 120;

public static void createDisplay() {

ContextAttribs attribs = new ContextAttribs(3,2);
attribs.withForwardCompatible(true);
attribs.withProfileCore(true);

try {
Display.setDisplayMode(new DisplayMode(WIDTH, HEIGHT));
Display.create(new PixelFormat(), attribs);
OpenGL opengl = new OpenGL();
GL11.glViewport(0, 0, WIDTH, HEIGHT);
} catch (LWJGLException e) {
e.printStackTrace();
}
}

public static void updateDisplay() {
Display.sync(FPS_CAP);
Display.update();
}

public static void closeDisplay() {

Display.destroy();

}

}

最佳答案

经过大量工作后,我最终决定阅读 Minecraft 的源代码,看看他们如何创建 OpenGL 窗口。我将其放入我的代码中,现在窗口可以完美打开!

如果遇到问题,要使其正常工作,请更换

Display.create(new PixelFormat(), attribs);

Display.create(new PixelFormat().withDepthBits(24));

关于java - 窗口打开时出错?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30147270/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com