Hello Guest

LWJGL3 - Changing screen resolution

  • 4 Replies
  • 5641 Views
*

Offline abcdef

  • ****
  • 322
LWJGL3 - Changing screen resolution
« 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?


Code: [Select]
    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();
    }

*

Offline SHC

  • **
  • 94
    • GoHarsha.com
Re: LWJGL3 - Changing screen resolution
« Reply #1 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.

*

Offline spasi

  • *****
  • 2172
    • WebHotelier
Re: LWJGL3 - Changing screen resolution
« Reply #2 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.

*

Offline abcdef

  • ****
  • 322
Re: LWJGL3 - Changing screen resolution
« Reply #3 on: January 09, 2015, 10:32:40 »
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

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

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: LWJGL3 - Changing screen resolution
« Reply #4 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.