Viewport::Viewport(int w, int h)
: width(w)
, height(h)
+, inverse_size(1.0f / float(width), 1.0f / float(height))
, fov(0.78539816339744830961f) // π/4
, aspect(float(w) / float(h))
, near(0.1f)
-, far(100.0f)
+, far(256.0f)
, perspective(glm::perspective(fov, aspect, near, far))
, ortho(glm::ortho(0.0f, float(width), float(height), 0.0f, near, far)) {
void Viewport::Resize(int w, int h) noexcept {
width = w;
height = h;
- aspect = float(width) / float(height);
+ float fw = float(w), fh = float(h);
+ inverse_size.x = 1.0f / fw;
+ inverse_size.y = 1.0f / fh;
+ aspect = fw / fh;
perspective = glm::perspective(fov, aspect, near, far);
- ortho = glm::ortho(0.0f, float(width), float(height), 0.0f, near, far);
+ ortho = glm::ortho(0.0f, fw, fh, 0.0f, near, far);
glViewport(0, 0, width, height);
}