LWJGL Forum

Programming => OpenGL => Topic started by: Zin on June 20, 2016, 19:18:55

Title: [Solved] How to avoid aspect ratios in GLFW
Post by: Zin on June 20, 2016, 19:18:55
So i have a project and when i make a window with 1:1 aspect ratio its 100% fine but when i change the size of the window it messes up and stretches the things on the screen how do i fix this?

Here are some photos
(http://i.stack.imgur.com/tnrEo.png)
(http://i.stack.imgur.com/NwmpF.png)
Title: Re: How to avoid aspect ratios in GLFW
Post by: Kai on June 20, 2016, 19:44:24
You have to modify the projection matrix to account for the aspect ratio.
If you haven't yet manipulated the projection matrix (which means you are using an orthographic projection) and are using the fixed-function pipeline, then the easiest solution is to add the following in your render loop before your rendering (or just when the window changes in size):

float aspect = (float)windowWidth/windowHeight;
GL11.glLoadIdentity();
GL11.glOrtho(-aspect, aspect, -1, 1, -1, 1);

or equivalently:

float aspect = (float)windowWidth/windowHeight;
GL11.glLoadIdentity();
GL11.glScale(1.0f/aspect, 1, 1);
Title: Re: How to avoid aspect ratios in GLFW
Post by: Zin on July 12, 2016, 02:02:15
i will try that soon thanks so much i will see if it works ;)
Title: Re: How to avoid aspect ratios in GLFW
Post by: Zin on July 12, 2016, 17:07:52
it doesn't fix the problem but thanks anyways :>
Title: Re: How to avoid aspect ratios in GLFW
Post by: Kai on July 12, 2016, 17:31:27
it usually does. you are probably doing something wrong then :>
Title: Re: How to avoid aspect ratios in GLFW
Post by: quew8 on July 12, 2016, 18:21:59
If you give a bit more info about how you are rendering we can tell you how to modify the projection matrix.
Title: Re: How to avoid aspect ratios in GLFW
Post by: Zin on July 14, 2016, 20:22:23
Its okay im restarting the project anyways
Title: Re: How to avoid aspect ratios in GLFW
Post by: Zin on September 10, 2016, 21:54:13
Quote from: Kai on June 20, 2016, 19:44:24
You have to modify the projection matrix to account for the aspect ratio.
If you haven't yet manipulated the projection matrix (which means you are using an orthographic projection) and are using the fixed-function pipeline, then the easiest solution is to add the following in your render loop before your rendering (or just when the window changes in size):

float aspect = (float)windowWidth/windowHeight;
GL11.glLoadIdentity();
GL11.glOrtho(-aspect, aspect, -1, 1, -1, 1);

or equivalently:

float aspect = (float)windowWidth/windowHeight;
GL11.glLoadIdentity();
GL11.glScale(1.0f/aspect, 1, 1);


thanks so much it works now that im using a alternative rendering method :)