I'm hoping someone can help me understand the GLViewport and what happens when we resize it
This will illustrate my confusion....
So, here I have a quad stuck in the middle of the screen. If I have my GLViewport match the device's width and height, I get what is on the first (left hand) picture. Exactly what I would expect.
- Device resolution, 2560 x 1600
- Viewport resolution 2560 x 1600
- Quad size 200 x 200 (Note, the image above is not to scale!!! :-))
- Quad shape, appears as square
Now, for the 2nd (right hand) picture...
- Device resolution, 2560 x 1600
- Viewport resolution 2560 x 1200 (and centered vertically)
- Quad size (200, 200)
- Quad shape, appears as rectangle
My question is, why is the quad displaying as a rectangle now and not a square? I've confirmed by logging that my quad is 200 x 200 pixes - surely the size of the physical pixels stays the same? They can't change. So what is going on here?
I thought (clearly incorrectly) that when I scaled the viewport, it literraly just chopped off pixels.
Would appreciate if someone could explain how this works.
Edit
Currently, I'm setting my viewport like this:
width = (int) Math.min(deviceWidth, deviceHeight * 1.702127659574468);
height = (int) Math.min(deviceHeight, deviceWidth / 1.702127659574468);
ratio = width / height;
GLES20.glViewport(offsetX, offsetY, width, height);
Matrix.orthoM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
offsetX and offsetY are just so that when there are letterboxes, the viewport is centered.
glScissor
instead ofglViewport
, it will simply crop pixels off without changing where anything is rendered.glViewport
behaves more like resizing the original image, rather than cropping it; that's why it squishes your box. \$\endgroup\$