当试图显示帧时,在当前线程中没有当前OpenGL上下文。它出现的行可能是GL.createCapabilities();(在私有方法Window.init中)我认为它失败了,因为glcontext没有初始化或类似的东西。
代码如下:
package com.engine.window;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.system.MemoryUtil.NULL;
import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import org.lwjgl.opengl.GLCapabilities;
/**
* The class {@code Window} represents a graphical frame.
* This is an abstract class that cannot be instantiated directly.
*/
public class Window { //abstract
public enum DisplayMode { FULLSCREEN, WINDOWED, BORDERLESS };
private DisplayMode mode;
private long window;
private java.awt.Rectangle bounds;
public Window(String title, int x, int y, int width, int height) {
GLFWErrorCallback.createPrint(System.err).set();
init();
if ((window = glfwCreateWindow(width, height, title, NULL, NULL)) != NULL) {
bounds = new java.awt.Rectangle(x, y, width, height);
glfwSetWindowPos(window, x, y);
glfwSetWindowSize(window, width, height);
glfwSetKeyCallback(window, (window, key, scancode, action, mods) -> {
if (key == GLFW_KEY_ESCAPE && action == GLFW_RELEASE) {
glfwSetWindowShouldClose(window, true);
}
});
glfwMakeContextCurrent(window);
GL.createCapabilities();
glfwShowWindow(window);
glfwFocusWindow(window);
} else {
throw new RuntimeException("Error: Failed to create the GLFW window.");
}
}
private void init() throws RuntimeException {
if (glfwInit()) {
glfwDefaultWindowHints();
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
long tmp = glfwCreateWindow(1, 1, "", NULL, NULL); //creating a temporary window to get the available opengl version
if (tmp != NULL) {
glfwMakeContextCurrent(tmp);
GL.createCapabilities();
GLCapabilities capabilities = GL.getCapabilities();
glfwDestroyWindow(tmp);
glfwDefaultWindowHints(); //resets window hints
if (capabilities.OpenGL32) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //avoids using old opengl
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_TRUE); //for mac os user
} else if (capabilities.OpenGL21) {
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
} else {
throw new RuntimeException("Error: Neither OpenGL 3.2 nor OpenGL 2.1 is supported.");
}
glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);
glfwWindowHint(GLFW_FOCUSED, GLFW_TRUE);
glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE);
glfwWindowHint(GLFW_CENTER_CURSOR, GLFW_TRUE);
glfwWindowHint(GLFW_SAMPLES, 4); //enables anti-aliasing
} else {
throw new RuntimeException("Error: Failed to create the GLFW window.");
}
} else {
throw new RuntimeException("Error: Failed to Initialize GLFW library.");
}
}
public void setMode(DisplayMode displayMode) {
long monitor = glfwGetPrimaryMonitor();
GLFWVidMode videoMode = glfwGetVideoMode(monitor);
if (displayMode == DisplayMode.FULLSCREEN) {
glfwSetWindowMonitor(window, monitor, 0, 0, videoMode.width(), videoMode.height(), 0);
} else if (displayMode == DisplayMode.WINDOWED) {
glfwSetWindowMonitor(window, NULL, bounds.x, bounds.y, bounds.width, bounds.height, 0);
} else if (displayMode == DisplayMode.BORDERLESS) {
glfwWindowHint(GLFW_RED_BITS,videoMode.redBits());
glfwWindowHint(GLFW_GREEN_BITS, videoMode.greenBits());
glfwWindowHint(GLFW_BLUE_BITS, videoMode.blueBits());
glfwWindowHint(GLFW_REFRESH_RATE, videoMode.refreshRate());
glfwSetWindowMonitor(window, monitor, 0, 0, videoMode.width(), videoMode.height(), videoMode.refreshRate());
}
mode = displayMode;
}
public void setMode(String displayMode) {
setMode(DisplayMode.valueOf(displayMode));
}
public void setVSync(boolean verticalSync) {
glfwMakeContextCurrent(window);
glfwSwapInterval(verticalSync ? 1 : 0);
}
public void pollEvents() {
glfwPollEvents();
}
public void swapBuffers() {
glfwSwapBuffers(window);
}
public boolean shouldClose() {
return glfwWindowShouldClose(window);
}
/**
* Release the resources and destroys windows and cursors.
*/
public void dispose() {
glfwDestroyWindow(window);
glfwTerminate();
glfwSetErrorCallback(null).free();
}
}
跟踪:
[java] [LWJGL] GLFW_NO_WINDOW_CONTEXT error
[java] Description : Cannot make current with a window that has no OpenGL or OpenGL ES context
[java] Stacktrace :
[java] org.lwjgl.glfw.GLFW.glfwMakeContextCurrent(GLFW.java:4522)
[java] com.engine.window.Window.<init>(Window.java:42)
[java] com.engine.window.Stage.<init>(Stage.java:14)
[java] com.engine.window.Stage.create(Stage.java:9)
[java] com.engine.application.Application.onstart(Application.java:73)
[java] com.engine.application.Application.setup(Application.java:60)
[java] com.engine.application.Plateform.launchApplication(Plateform.java:27)
[java] com.engine.application.Application.launch(Application.java:39)
[java] Launcher.main(Launcher.java:9)
[java] [LWJGL] An OpenGL context was in an error state before the creation of its capabilities instance. Error: 0x502
[java] Exception in thread "main" java.lang.RuntimeException: Error: Failed to create and initialize a new instance of the constructor's declaring class : class Launcher.
[java] at com.engine.application.Plateform.launchApplication(Plateform.java:29)
[java] at com.engine.application.Application.launch(Application.java:39)
[java] at Launcher.main(Launcher.java:9)
[java] Caused by: java.lang.IllegalStateException: There is no OpenGL context current in the current thread.
[java] at org.lwjgl.opengl.GL.createCapabilities(GL.java:378)
[java] at org.lwjgl.opengl.GL.createCapabilities(GL.java:322)
[java] at com.engine.window.Window.<init>(Window.java:43)
[java] at com.engine.window.Stage.<init>(Stage.java:14)
[java] at com.engine.window.Stage.create(Stage.java:9)
[java] at com.engine.application.Application.onstart(Application.java:73)
[java] at com.engine.application.Application.setup(Application.java:60)
[java] at com.engine.application.Plateform.launchApplication(Plateform.java:27)
[java] ... 2 more
[java] Java Result: 1
在< code>init()中,您通过调用< code > glfwWindowHint(GLFW _ CLIENT _ API,GLFW_NO_API)显式地告诉GLFW不要为任何进一步创建的窗口创建任何OpenGL上下文;。
因此,您在< code>init()返回后创建的窗口将不会为其创建OpenGL上下文。
< code>GLFW_CLIENT_API窗口提示的默认值是< code>GLFW_OPENGL_API,因此,如果您希望创建的第二个窗口也具有OPENGL上下文,只需不设置该窗口提示即可。
我正在尝试使用GLFW创建一个窗口。窗口已创建,但经过几次尝试,创建窗口需要很长时间。 https://drive.google.com/file/d/1zq4IEjcSIJxy5wnXWLrGe46ptHMbKM5R/view?usp=sharing 我找不到任何解决办法,也不知道这是由什么引起的。 这是我正在使用的代码: 程序输出为 所以看起来初始化glfw需要很长时间,但我不知道如何修复它。
我们的机器上有Maven。我们使用的是Maven 2.2.1和CentOS 6.0。当我们使用以下命令创建基础项目时 mvn原型:创建-e-Darch etypeGroupId=com.jivesoftware.maven-Darch etypeartifactId=maven-jive-plugin-ArchetypeVersion=5.0.2-SNAPSHOT-Dgroup pId=com.d
我正在尝试使用GLFW3创建一个窗口。当我在我的桌面上做这件事时,效果很好。在我的笔记本电脑上,它无法创建窗口,程序崩溃。删除glfwWindowHint()调用可以防止崩溃,但我的代码无法工作,因为我使用了错误的openGL版本。以下是窗口代码: 这可能与我的台式机有NVidia图形,而我的笔记本电脑有集成图形有关吗? 更新:它在调用glfwSwapBuffers()时崩溃,我将glfw错误65
问题内容: 我有一个主Frame(称为)和一个弹出式Toplevel(称为)。如何确保用户在“处于活动状态”时无法单击任何内容? 问题答案: 如果您不想隐藏根目录,而只是确保用户只能与弹出窗口进行交互,则可以使用和。 或者 ,您可以使它不可见的根源: 将保留根,但仅可见。 如果您需要它,可以做
我试图用PHPJasper创建一些代码,但在同一行我得到了错误。我认为这是JavaSE版本的问题。 文件已经存在于我的项目中。 源代码: 控制台中带有的行出现错误: Java版本: 我怎么才能修好它?
E/AndroidRuntime:致命异常:main process:com.luteraa.luteraaesports,pid:6355 java.lang.nullpointerException:试图在com.luteraa.luteraaesports.bgmicategoryAdapter.OpenDialog(bgmicategoryAdapter.java.access$000(b