I'm using 3d mode to render my 2d game, because the camera rotation and zooming in/out is much easier than with 2d mode.
Now i have ran into a problem i cant seem to think how to fix:
My texcoords start from 0 and ends to 1, so i can see all the pixels from one tile in the GL_NEAREST texture filter mode.
My window is resizeable in a way that my tiles are always squares but the visible area expands depending on how i resize my window.
Edit: my view port is using perspective mode, not isometric. but if its not possible in perspective mode, im willing to change to isometric.
Use an orthographic projection that maps eye space units to pixels:
glViewport(0,0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);
A texel → viewport pixel matching is possible with a perspective projection, but only under a certain constraint: The textured quad must be coplanar to the perspective frustum near/far plane.
How to do it? For glFrustum(left, right, bottom, top, near, far)
with Z=near, XY eye space range [left, right]×[bottom, top] maps to NDC xy[-1, 1]² and NDC xy[-1, 1]² maps to the viewport extents. So those are all affine transformations following the law
y(x) = to_lower_bound + (x - from_lower_bound) * (to_upper_bound - to_lower_bound) / (from_upper_bound - from_lower_bound)
All you have to do it map viewport to NDC to near plane and if you're Z =/= near scale by near/Z.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With