Draw Ratio by width and height instead of just width

Started by YesImAHuman, August 18, 2017, 20:01:57

Previous topic - Next topic

YesImAHuman

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?

Kai

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:
float aspect = (float)windowWidth/windowHeight;
glOrtho(-aspect, aspect, -1, +1, -1, +1);