LWJGL Forum

Programming => Lightweight Java Gaming Library => Topic started by: abcdef on January 09, 2015, 07:15:47

Title: LWJGL3 - Changing screen resolution
Post by: abcdef on January 09, 2015, 07:15:47
Hi

I have an issue and its probably a stupid error on my part. I am currently using the latest nightly build of LWJGL3.

I am trying to change the screen resolution (not full screen but windowed mode) after selecting an item in a list box, the current outcome of this is the original window gets destroyed and a new window gets created. The call backs were released before the old window was destroyed and new ones we added to the new window. Mouse and keyboard call back information works perfectly in both the old and the new, the issue is I am getting a black screen with nothing drawn. The draw loop is still running but nothing is showing in the new window.

The code I use to initialise the first window (which works fine) and the new window (which doesn't work) is shown below.

Can anyone think why the new window isn't displaying graphics?



    public void setDisplay(DisplayData displayData, boolean fullScreen) throws DarkYellowException
    {
        // if we have a window already destroy it so we can create a new one
        if (window != MemoryUtil.NULL)
        {
            fireWindowDestroyEvent();
            GLFW.glfwDestroyWindow(window);
        }

        GLFW.glfwDefaultWindowHints();
        GLFW.glfwWindowHint(GLFW.GLFW_VISIBLE, GL_FALSE);
        GLFW.glfwWindowHint(GLFW.GLFW_RESIZABLE, GL_TRUE);

        // tell the window what bits per pixel we are interested in
        GLFW.glfwWindowHint(GLFW.GLFW_RED_BITS, displayData.getRedDepth());
        GLFW.glfwWindowHint(GLFW.GLFW_GREEN_BITS, displayData.getGreenDepth());
        GLFW.glfwWindowHint(GLFW.GLFW_BLUE_BITS, displayData.getBlueDepth());
        GLFW.glfwWindowHint(GLFW.GLFW_OPENGL_PROFILE, GLFW.GLFW_OPENGL_CORE_PROFILE);
        GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MAJOR, 3);
        GLFW.glfwWindowHint(GLFW.GLFW_CONTEXT_VERSION_MINOR, 2);       

        // create the actual window
        if (fullScreen)
        {
            window = GLFW.glfwCreateWindow(displayData.getWidth(), displayData.getHeight(), "", GLFW.glfwGetPrimaryMonitor(), MemoryUtil.NULL);
        } else
        {
            window = GLFW.glfwCreateWindow(displayData.getWidth(), displayData.getHeight(), "", MemoryUtil.NULL, MemoryUtil.NULL);
        }

        if (window == MemoryUtil.NULL)
        {
            throw new Exception("Failed to create the window");
        }

        // if windowed then center
        if (!fullScreen)
        {
            ByteBuffer vidmode = GLFW.glfwGetVideoMode(GLFW.glfwGetPrimaryMonitor());
            GLFW.glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - displayData.getWidth()) / 2, (GLFWvidmode.height(vidmode) - displayData.getHeight()) / 2);
        }
       
        GLFW.glfwMakeContextCurrent(window);
        GLContext.createFromCurrent();
        GL11.glViewport(0, 0, displayData.getWidth(), displayData.getHeight());
        GLFW.glfwSwapInterval(1);

        GLFW.glfwShowWindow(window);
        fireWindowCreateEvent();
    }
Title: Re: LWJGL3 - Changing screen resolution
Post by: SHC on January 09, 2015, 08:26:46
I have seen this issue before, the solution in my case was that I have to re-create VAOs and setup the pointers. This is because VAOs cannot be shared across OpenGL contexts.
Title: Re: LWJGL3 - Changing screen resolution
Post by: spasi on January 09, 2015, 09:16:35
A note on callbacks, unrelated to the issue: You do not have to release and re-create them. You can think of callbacks as stateless function pointers, you can freely use them with as many windows as you like.
Title: Re: LWJGL3 - Changing screen resolution
Post by: abcdef on January 09, 2015, 10:32:40
Quote from: SHC on January 09, 2015, 08:26:46
I have seen this issue before, the solution in my case was that I have to re-create VAOs and setup the pointers. This is because VAOs cannot be shared across OpenGL contexts.

Thanks I'll give that a try

Quote from: spasi on January 09, 2015, 09:16:35
A note on callbacks, unrelated to the issue: You do not have to release and re-create them. You can think of callbacks as stateless function pointers, you can freely use them with as many windows as you like.

That's good to know, I will just reuse them with the new window
Title: Re: LWJGL3 - Changing screen resolution
Post by: quew8 on January 09, 2015, 17:46:01
Well in the code you have posted, you aren't actually sharing the OpenGL context. To share OpenGL contexts (from memory) you need to pass the pointer of the old window as the last parameter of glfwCreateWindow(). Maybe you don't mean to share contexts but if that is so then you need to recreate all OpenGL objects and reset all OpenGL state and it is probably here where there is a mistake.