1

我最近开始使用 lwjgl 并且没有遇到任何问题。昨天我去创建一个新窗口(我已经做了至少十几次,如果不是更多的话),当我运行它时它给出了这些错误

Exception in thread "main" java.lang.RuntimeException: No OpenGL context found in the current thread.
    at org.lwjgl.opengl.GLContext.getCapabilities(GLContext.java:124)
    at org.lwjgl.opengl.GL11.glMatrixMode(GL11.java:2051)
    at Main.initGL(Main.java:10)
    at Main.main(Main.java:34)

我的代码是

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import static org.lwjgl.opengl.GL11.*;

public class Main
{
    public static void initGL()
    {
        glMatrixMode(GL_PROJECTION);
        glLoadIdentity();
        glOrtho(0, 640, 480, 0, 1, -1);
        glMatrixMode(GL_MODELVIEW);
    }

    public static void initDisplay()
    {
        try 
        {
            Display.setDisplayMode(new DisplayMode(480, 600));
            Display.setTitle("Texture Demo");
            Display.create();
        }

        catch (LWJGLException e) 
        {
            e.printStackTrace();
        }
        Display.update();
    }

    public static void main(String[] args)
    {
        initGL();
        initDisplay();
    }
}

我看不到任何错误,就像我说的,我之前运行过这段代码。

4

3 回答 3

3

initGL并且initDisplay绕错了方向。

GL 需要一个上下文,然后才能开始调用 GL 函数,so initDisplay()and then initGL()

于 2014-03-06T06:00:28.870 回答
1

我最近在做游戏时遇到了这个问题。OpenGL 初始化需要在 Display 创建之后进行。而且,您必须不断更新您的显示器,否则它会在创建时立即关闭。这里有一个例子:

    public void run() {
        while(!Display.isCloseRequested) {
            Display.update()
            // Add repainting and input here
        }
    }   

并在“main”方法中添加“run”方法

于 2013-08-12T20:23:05.250 回答
0

如果您更改初始化状态,它将起作用。所以首先你必须做 initDisplay() 因为矩阵不会找到 OpenGL 的显示。

于 2013-07-07T18:41:03.287 回答