No OpenGL context found in the current thread, how do I fix this error?

后端 未结 5 639
不思量自难忘°
不思量自难忘° 2020-12-02 01:49

I\'m working on a card game, and currently have a good foundation but I\'m running into an error when I run it in eclipse. I\'m also using slick 2d.

Here is the erro

相关标签:
5条回答
  • 2020-12-02 02:13

    This kind of error is common for LWJGL starters. The OpenGL context gets bound to a thread when it's been created. So you can only access this context from the same thread.

    As it does not look that you're working with different threads there might be another cause. Slick2D seems to need a valid OpenGL context for its Image class.

    So my first try would be to initialize an OpenGL context before initializing your card images.

    0 讨论(0)
  • 2020-12-02 02:16

    An old thread, but it might help someone. Depending on which LWJGL you're using, init your Display:

    LWJGL 3 (uses GLFW):

    if (!glfwInit()) {
       throw new IllegalStateException("Can't init GLFW");
    }
    

    LWJGL 2:

    try {
       Display.setDisplayMode(new DisplayMode(800, 600));
       Display.create();
    } catch (LWJGLException ex) {
       Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }
    

    I, mostly, forget Display.create() :)

    0 讨论(0)
  • 2020-12-02 02:17

    In lwjgl 3.x and higher, you can try: GLContext.createFromCurrent();

    If you're using libgdx, there is also Gdx.app.postRunnable(...) to post a Runnable on the render thread.

    0 讨论(0)
  • 2020-12-02 02:27

    This happened to me once, and I couldn't figure out what to do until I realized I was calling the image loader before OpenGL had initialized. Make sure that you aren't defining any variables with an image loader in the constructor(or any other method called) before OpenGL inits(what I did).

    Are you defining a Card class before OpenGL is initialized?

    Hope this helps.

    0 讨论(0)
  • 2020-12-02 02:31

    Well, what I've found is that you need to init your Display before you set your OpenGL environment :)...

    0 讨论(0)
提交回复
热议问题