So I am working on a simple project in openGL and C++ where i have just a white circle drawn on screen for now.
I added a function to maintain the aspect ratio in the canvas i am using and it seems to be working flawlessly.
If you resize the window horizontally, clipping will occur (this is what i intended)
But if you resize the window vertically, no clipping occurs and instead the objects scale down/up..
Now i am stuck at figuring out how to keep the aspect ratio correct, while also preventing the objects from scaling and while keeping in mind that i will be implementing Panning and Zoom later on.
With that in mind, here is the code i am using to adjust the ratio.
Please note that glViewPort is also set correctly on resize, but i only copied this section because i know the problem is somewhere here.
if ( dx/dy < w/h ){
// Need to expand dx
GLdouble diff = w/h*dy - dx;
minX -= 0.5*diff;
maxX += 0.5*diff;
}
else{
// Need to shrink dx
GLdouble diff = h/w * dx - dy;
minX += 0.5*diff;
maxX -= 0.5*diff;
}
glOrtho( minX, maxX, minY, maxY, minZ, maxZ );