[Solved] How to avoid aspect ratios in GLFW

Started by Zin, June 20, 2016, 19:18:55

Previous topic - Next topic

Zin

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


Kai

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);

Zin

i will try that soon thanks so much i will see if it works ;)

Zin

it doesn't fix the problem but thanks anyways :>

Kai

it usually does. you are probably doing something wrong then :>

quew8

If you give a bit more info about how you are rendering we can tell you how to modify the projection matrix.

Zin

Its okay im restarting the project anyways

Zin

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 :)