How to scale the 2nd world with 3D rendering?

I use 3D mode to render my 2nd game, because rotating the camera and zooming in / out is much easier than using 2d mode.

Now I am facing a problem that I cannot think of how to fix:

  • How do I make the 2d plane of my world fit the screen so that 1 pixel of the texture corresponds to 1 pixel on my screen? In other words: how to calculate the z-position of my camera to achieve this?

My texcoords start at 0 and end at 1, so I can see all the pixels from the same tile in the GL_NEAREST texture filter mode.

My window is resized so that my tiles are always square, but the visible area expands depending on how I resize the window.

Edit: my viewport uses perspective mode, not isometric. but if this is not possible in perspective mode, they want to switch to isometric.

+5
source share
1 answer

Use spelling projection, which displays units of eye space in pixels:

glViewport(0,0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, width, 0, height, -1, 1);

Update due to question update:

Pixel matching in pixels can be used with perspective projection, but only with a certain restriction: the textured square must be coplanar to the perspective truncation of the near / far plane.

? glFrustum(left, right, bottom, top, near, far) Z = XY [, ] × [, ] NDC xy [-1, 1] ² NDC xy [-1, 1] ² , ,

y(x) = to_lower_bound + (x - from_lower_bound) * (to_upper_bound - to_lower_bound) / (from_upper_bound - from_lower_bound)

, , - , Z =/= /Z.

+2

All Articles