1

I've recently started to use the lwjgl and haven't run into any problems. Yesterday I went to create a new window (something I've done at least a dozen times, if not more) and it gave these errors when I ran it

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)

My code is

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();
    }
}

I can't see any errors and like I said, I've ran this code before.

genpfault
  • 51,148
  • 11
  • 85
  • 139
Braeden Orchard
  • 235
  • 2
  • 12
  • 1
    Check ***[this](http://stackoverflow.com/questions/14926929/java-lang-runtimeexception-no-opengl-context-found-in-the-current-thread)*** and ***[this](http://stackoverflow.com/questions/15950151/no-opengl-context-found-in-the-current-thread)*** posts – Extreme Coders Apr 27 '13 at 07:17

3 Answers3

3

initGL and initDisplay are round the wrong way.

GL needs a context before you can start calling GL functions, so initDisplay() and then initGL().

jozxyqk
  • 16,424
  • 12
  • 91
  • 180
1

I have had this problem recently while making a game. The OpenGL initialization needs to be after the Display creation. And also, you must constantly update your Display or else it will immediately close on creation. An example here:

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

And add the "run" method in your "main" method

0

If you change the init states it will work. So At first you have to do the initDisplay() beacuse the matrices will not find the OpenGL's display.

Csoki
  • 119
  • 1
  • 2
  • 11