Hello Guest

[Solved] How to avoid aspect ratios in GLFW

  • 7 Replies
  • 9425 Views
*

Offline Zin

  • *
  • 15
[Solved] How to avoid aspect ratios in GLFW
« 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

« Last Edit: September 12, 2016, 20:04:23 by Zin »

*

Kai

Re: How to avoid aspect ratios in GLFW
« Reply #1 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):
Code: [Select]
float aspect = (float)windowWidth/windowHeight;
GL11.glLoadIdentity();
GL11.glOrtho(-aspect, aspect, -1, 1, -1, 1);
or equivalently:
Code: [Select]
float aspect = (float)windowWidth/windowHeight;
GL11.glLoadIdentity();
GL11.glScale(1.0f/aspect, 1, 1);
« Last Edit: June 20, 2016, 20:13:03 by Kai »

*

Offline Zin

  • *
  • 15
Re: How to avoid aspect ratios in GLFW
« Reply #2 on: July 12, 2016, 02:02:15 »
i will try that soon thanks so much i will see if it works ;)

*

Offline Zin

  • *
  • 15
Re: How to avoid aspect ratios in GLFW
« Reply #3 on: July 12, 2016, 17:07:52 »
it doesn't fix the problem but thanks anyways :>

*

Kai

Re: How to avoid aspect ratios in GLFW
« Reply #4 on: July 12, 2016, 17:31:27 »
it usually does. you are probably doing something wrong then :>

*

Offline quew8

  • *****
  • 569
  • Because Square Eyes Look More Real
Re: How to avoid aspect ratios in GLFW
« Reply #5 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.

*

Offline Zin

  • *
  • 15
Re: How to avoid aspect ratios in GLFW
« Reply #6 on: July 14, 2016, 20:22:23 »
Its okay im restarting the project anyways

*

Offline Zin

  • *
  • 15
Re: How to avoid aspect ratios in GLFW
« Reply #7 on: September 10, 2016, 21:54:13 »
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):
Code: [Select]
float aspect = (float)windowWidth/windowHeight;
GL11.glLoadIdentity();
GL11.glOrtho(-aspect, aspect, -1, 1, -1, 1);
or equivalently:
Code: [Select]
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 :)