any call to a method with gl in it Causes "Illegal State Exception"

Started by snocavotia, July 09, 2015, 05:08:22

Previous topic - Next topic

snocavotia

Hey guys. So i've been trying to get started with the new lwjgl 3 but ive hit a few roadblocks along the way. Today i was making progress until I started setting up my rendering methods. now anytime I call "some" methods from GL11 like glBegin() i get an IllegalStateException. Strangely glClear() doesnt give me any errors.

Kai

- does the demo program on http://www.lwjgl.org/guide work?
- what is the message of the IllegalStateException? Is it possibly: "There is no OpenGL context current in the current thread." ?
- are you using multiple threads?
- are you on OS X? In which case you should use the JVM argument "-XstartOnFirstThread".

About the OpenGL context needing to be current:
OpenGL requires a context to be "current" in the thread that calls GL functions. Being current means that OpenGL knows which context the GL function applies to and on which window the result will be rendered to.
You therefore need to make sure that, before calling any GL functions, you have called GLFW.glfwMakeContextCurrent(window) with the GLFW window as argument AND that you notified LWJGL about the current context once via GLContext.createFromCurrent().

spasi

You're probably calling deprecated functions in a core/forward-compatible context.

quew8

You can set the requested OpenGL version, forward compatibility setting and OpenGL profile with the following function calls BEFORE calling glfwCreateWindow():

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, majorVersion);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minorVersion);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, forwardCompatible);
glfwWindowHint(GLFW_OPENGL_PROFILE, profile);

"forwardCompatible" must be either "GL_TRUE" or "GL_FALSE".

"profile" must one of the following: "GLFW_OPENGL_CORE_PROFILE", "GLFW_OPENGL_COMPAT_PROFILE" or "GLFW_OPENGL_ANY_PROFILE".

It's all here. http://javadoc.lwjgl.org/

snocavotia

Quote from: Kai on July 09, 2015, 08:00:26
- does the demo program on http://www.lwjgl.org/guide work?
- what is the message of the IllegalStateException? Is it possibly: "There is no OpenGL context current in the current thread." ?
- are you using multiple threads?
- are you on OS X? In which case you should use the JVM argument "-XstartOnFirstThread".

About the OpenGL context needing to be current:
OpenGL requires a context to be "current" in the thread that calls GL functions. Being current means that OpenGL knows which context the GL function applies to and on which window the result will be rendered to.
You therefore need to make sure that, before calling any GL functions, you have called GLFW.glfwMakeContextCurrent(window) with the GLFW window as argument AND that you notified LWJGL about the current context once via GLContext.createFromCurrent().

Yes that demo works Quite fine.

The message is "Exception in thread "main" java.lang.IllegalStateException: This function is not available."

I am not using multiple threads, and am on Windows 7.

snocavotia

Quote from: quew8 on July 09, 2015, 10:42:02
You can set the requested OpenGL version, forward compatibility setting and OpenGL profile with the following function calls BEFORE calling glfwCreateWindow():

glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, majorVersion);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, minorVersion);
glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, forwardCompatible);
glfwWindowHint(GLFW_OPENGL_PROFILE, profile);

"forwardCompatible" must be either "GL_TRUE" or "GL_FALSE".

"profile" must one of the following: "GLFW_OPENGL_CORE_PROFILE", "GLFW_OPENGL_COMPAT_PROFILE" or "GLFW_OPENGL_ANY_PROFILE".

It's all here. http://javadoc.lwjgl.org/

So i was playing around with the profiles and this is what i had initially:
        ContextCapabilities caps = GL.getCapabilities();
        glfwDestroyWindow(temp);

        // Reset and set window hints
        glfwDefaultWindowHints();
        if (caps.OpenGL32) {
            // Hints for OpenGL 3.2 core profile
            glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
            glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
            glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
            glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_FALSE);
        } else if (caps.OpenGL21) {
            // Hints for legacy OpenGL 2.1
            glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 2);
            glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
        } else {
            throw new RuntimeException("Neither OpenGL 3.2 nor OpenGL 2.1 is "
                    + "supported, you may want to update your graphics driver.");
        }


After changing GLFW_OPENGL_CORE_PROFILE to GLFW_OPENGL_COMPAT_PROFILE I no longer recieved that error but I get some "wicked" display flickering. Not sure if thats solving the problem or making it worse xD.

snocavotia

Quote from: spasi on July 09, 2015, 09:07:15
You're probably calling deprecated functions in a core/forward-compatible context.

Can you explain what this means? I believe this may be right, due to after me changing "GLFW_OPENGL_CORE_PROFILE" to "GLFW_OPENGL_COMPAT_PROFILE" the error no longer occured.

quew8

So come OpenGL 3.0, a whole bunch of legacy functions were marked as deprecated. Then come OpenGL 3.2 profiles were introduced. You can either get core OpenGL which is minus the deprecated features or compatibility, which is including all the deprecated features. The there's forward compatibility which is a whole other kettle of fish. (read all about it here: https://www.opengl.org/wiki/Core_And_Compatibility_in_Contexts)

Included in the deprecation was the fixed function pipeline (all the functions like glTranslate(), glLoadMatrix(), glOrtho() as well as anything to do with lighting and a few other things) and the immediate mode rendering (glBegin() glVertexXX() glTexCoordXX etc. etc.). They are replaced with the programmable pipeline (shaders) and deferred rendering (using buffers for vertex data instead).