英文:
Problem with creating a window using GLFW (LWJGL)
问题
我正在尝试使用GLFW创建一个窗口。窗口已经创建,但在尝试几次后,在窗口创建之前需要等待很长时间。
这里是我正在使用的代码:
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.glfw.GLFW.*;
public class Main {
public static void main(String[] args) {
System.out.println("0");
if (!glfwInit()) {
throw new IllegalStateException("GLFW couldn't be initialized!");
}
System.out.println("1");
long window = glfwCreateWindow(450, 800, "Test #1", 0, 0);
if (window == 0) {
throw new IllegalStateException("GLFW failed to create a window!");
}
System.out.println("2");
GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window, (videoMode.width() - 450) / 2, (videoMode.height() - 800) / 2);
glfwMakeContextCurrent(window);
GL.createCapabilities();
float i = 2;
float speed = 1;
System.out.println("3");
while (!glfwWindowShouldClose(window)) {
if (i > 253 || i < 1)
speed *= -1;
i += speed;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glColor4f(0.38f, (i % 255) / 255, (i % 255) / 255, 1.0f);
glVertex2f(-0.5f, 0.5f);
glVertex2f(0.5f, 0.5f);
glVertex2f(0.5f, -0.5f);
glVertex2f(-0.5f, -0.5f);
glEnd();
glfwSwapBuffers(window);
glfwPollEvents();
}
System.out.println("4");
glfwDestroyWindow(window);
glfwTerminate();
System.out.println("5");
}
}
程序的输出是
0
//现在要等很长时间
1
2
3
看起来似乎需要很长时间来初始化GLFW,但我不知道如何修复它。
英文:
I'm trying to create a window using GLFW. Window IS created,
but after a few attempts it takes really long before window is created.
https://drive.google.com/file/d/1zq4IEjcSIJxy5wnXWLrGe46ptHMbKM5R/view?usp=sharing
I can't find any solution for this and don't know what can this be caused by.
Here's a code I am using:
import org.lwjgl.glfw.GLFWVidMode;
import org.lwjgl.opengl.GL;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.glfw.GLFW.*;
public class Main {
public static void main(String[] args) {
System.out.println("0");
if(!glfwInit()) {
throw new IllegalStateException("GLFW couldn't be initialized!");
}
System.out.println("1");
long window = glfwCreateWindow(450,800,"Test #1",0,0);
if(window == 0) {
throw new IllegalStateException("GLFW failed to create a window!");
}
System.out.println("2");
GLFWVidMode videoMode = glfwGetVideoMode(glfwGetPrimaryMonitor());
glfwSetWindowPos(window,(videoMode.width()-450)/2,(videoMode.height()-800)/2);
glfwMakeContextCurrent(window);
GL.createCapabilities();
float i = 2;
float speed = 1;
System.out.println("3");
while(!glfwWindowShouldClose(window)) {
if(i> 253 || i < 1)
speed *= -1;
i+=speed;
glClear(GL_COLOR_BUFFER_BIT);
glBegin(GL_QUADS);
glColor4f(0.38f,(i%255)/255,(i%255)/255,1.0f);
glVertex2f(-0.5f,0.5f);
glVertex2f(0.5f,0.5f);
glVertex2f(0.5f, -0.5f);
glVertex2f(-0.5f,-0.5f);
glEnd();
glfwSwapBuffers(window);
glfwPollEvents();
}
System.out.println("4");
glfwDestroyWindow(window);
glfwTerminate();
System.out.println("5");
}
}
Program's output is
0
//Now for a really long time nothing
1
2
3
So it looks like it takes really long to initialize glfw, but I have no idea how to fix it.
答案1
得分: 0
经过一些研究,我发现问题与USB输入设备有关 - 在我的情况下是Corsair k55键盘。
根据一些文章和GitHub问题,我了解到这个问题也是由一些其他设备引起的(在许多情况下是Corsair,但不仅限于此)。
解决方法是:
- 找出是哪个设备引起了问题(通过拔掉设备,这是我解决问题的方式)
- 现在(如我发现它是我的k55)我必须更新ICUE(驱动程序)。
希望能帮助到你
英文:
After some research I found out, that the problem was related to USB Input Device - in my case - Corsair k55 keyboard.
From some articles and github issues I learend, that that bug is also caused by some other devices (In many cases Corsair, but not only).
The fix is:
- to find out which device causes the bug (by unpluging, that's how I did)
- now (as I found it's my k55) I had to update ICUE (drivers).
Hope it helps
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论