创建窗口使用GLFW (LWJGL)时出现问题。

huangapple go评论72阅读模式
英文:

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(&quot;0&quot;);
             if(!glfwInit()) {
                 throw  new IllegalStateException(&quot;GLFW couldn&#39;t be initialized!&quot;);
             }
             System.out.println(&quot;1&quot;);
    
             long window = glfwCreateWindow(450,800,&quot;Test #1&quot;,0,0);
    
             if(window == 0) {
                throw new IllegalStateException(&quot;GLFW failed to create a window!&quot;);
             }
             System.out.println(&quot;2&quot;);
    
            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(&quot;3&quot;);
             while(!glfwWindowShouldClose(window)) {
            	 
            	 if(i&gt; 253 || i &lt; 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(&quot;4&quot;);
             glfwDestroyWindow(window);
             glfwTerminate();
             System.out.println(&quot;5&quot;);
    
        }
    }

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(驱动程序)。

希望能帮助到你 创建窗口使用GLFW (LWJGL)时出现问题。

英文:

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 创建窗口使用GLFW (LWJGL)时出现问题。

huangapple
  • 本文由 发表于 2020年8月10日 01:24:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/63329314.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定