LWJGL Forum

Please login or register.

Login with username, password and session length

Author Topic: Draw Ratio by width and height instead of just width  (Read 114 times)

YesImAHuman

  • Newbie
  • *
  • Offline Offline
  • Posts: 1
Draw Ratio by width and height instead of just width
« on: August 18, 2017, 20:01:57 »

hello, ive recently stepped into LWJGL and the first problem i encountered is that when rescaling the window it will rescale the textures according to the width AND height, which is not really what i want because squares will turn up into rectangles

ive tried using gluPerspective which does the same, i tried glOrtho which also does the same,
so im asking nicely, can somebody help me by just giving an general direction of what method i should use?
Logged

Kai

  • Guest
Re: Draw Ratio by width and height instead of just width
« Reply #1 on: August 19, 2017, 09:28:43 »

When you want a perspective projection then have a look at the second parameter described in the documentation of gluPerspective.

When you want an orthographic projection using glOrtho, then you have to scale the values for the "left" and "right" parameters accordingly to account for the wider (or narrower) field of view along the horizontal axis:
Code: [Select]
float aspect = (float)windowWidth/windowHeight;
glOrtho(-aspect, aspect, -1, +1, -1, +1);
Logged