LWJGL Forum

Programming => OpenGL => Topic started by: lucasfraser on January 10, 2016, 07:00:02

Title: GLFW window resizing
Post by: lucasfraser on January 10, 2016, 07:00:02
Hi Guys,

I'm sure I've just missed something silly, but I've been trying to make my game window re sizable and all I can seem to get is everything staying down the bottom left corner (Image 2).

In the glfwSetFramebufferSizeCallback() method I have set my global width and height variables and updated my GLOrtho projection (for GUI/HUD components) and also my View and Projection matrices (for rendering the 3D stuff).

When the window is re sized, the content in the corner seems to scale as per the updated matrices (see 2 images), but the actual OpenGL canvas? that they are drawn onto doesn't scale up to the new size of the window.

Would there be something silly I've overlooked? or is there another issue deeper in my codebase?

Cheers,
Lucas
Title: Re: GLFW window resizing
Post by: abcdef on January 10, 2016, 07:13:32
Do you call the glViewPort method after the resize has happened / is happening?
Title: Re: GLFW window resizing
Post by: lucasfraser on January 10, 2016, 07:17:54
Hi there,

No I was not, but I have added that and it hasn't seemed to work :/.

This is the code for my callback:
glfwSetWindowSizeCallback(window, windowSizeCallback = new GLFWWindowSizeCallback(){
            @Override
            public void invoke(long window, int width, int height){
                Game.WIDTH = width;
                Game.HEIGHT = height;
                Game.aspectRatio = (float)Game.WIDTH / (float)Game.HEIGHT;

                //Updates the matrices
                gfx.initGL();
                Camera.initMatricies();

                glViewport(0, 0, WIDTH, HEIGHT);
            }
        });


Thanks for your help!

Lucas
Title: Re: GLFW window resizing
Post by: lucasfraser on January 10, 2016, 09:02:24
Hello again,

Sorry for the false information, It appears I've solved the issue now. I didnt call glViewPort() before I updated my projection.

So in summary, my code is now:
glfwSetWindowSizeCallback(window, windowSizeCallback = new GLFWWindowSizeCallback(){
            @Override
            public void invoke(long window, int width, int height){
                Game.WIDTH = width;
                Game.HEIGHT = height;
                Game.aspectRatio = (float)Game.WIDTH / (float)Game.HEIGHT;
                glViewport(0, 0, Game.WIDTH, Game.HEIGHT);
                gfx.initGL();
                Camera.initMatricies();
            }
        });


Thanks for the help! I think the glViewPort use with resizing should be mentioned somewhere because I didn't find it during my searches.

Cheers,
Lucas
Title: Re: GLFW window resizing
Post by: Hydroque on February 11, 2016, 00:02:50
Make sure your shader adheres to you width and height changes. I.E. not statically implemented.