@@ -27,6 +27,9 @@ static bool htl_2d_matrix_set = false;
2727
2828static bool matrix_uniform_up_to_date = false ;
2929
30+ static bool gr_ortho_override_active = false ;
31+ static float gr_ortho_override_distance = 0 .0f ;
32+
3033static matrix4 create_view_matrix (const vec3d* pos, const matrix* orient)
3134{
3235 vec3d scaled_pos;
@@ -127,7 +130,18 @@ void gr_set_proj_matrix(fov_t fov, float aspect, float z_near, float z_far) {
127130
128131 gr_last_projection_matrix = gr_projection_matrix;
129132
130- if (std::holds_alternative<float >(fov)) {
133+ if (gr_ortho_override_active && std::holds_alternative<float >(fov)) {
134+ float half_h = gr_ortho_override_distance * tanf (std::get<float >(fov) * 0 .5f );
135+ float half_w = half_h * aspect;
136+ if (gr_screen.rendering_to_texture != -1 ) {
137+ create_orthographic_projection_matrix (&gr_projection_matrix, -half_w, half_w, half_h, -half_h, z_near, z_far);
138+ } else {
139+ create_orthographic_projection_matrix (&gr_projection_matrix, -half_w, half_w, -half_h, half_h, z_near, z_far);
140+ }
141+ // Clear after the first call so that shadow/deferred
142+ // restore calls later in the same frame are not affected
143+ gr_ortho_override_active = false ;
144+ } else if (std::holds_alternative<float >(fov)) {
131145 float clip_width, clip_height;
132146 clip_height = tan (std::get<float >(fov) * 0 .5f ) * z_near;
133147 clip_width = clip_height * aspect;
@@ -393,3 +407,15 @@ void gr_matrix_set_uniforms()
393407
394408 matrix_uniform_up_to_date = true ;
395409}
410+
411+ void gr_activate_ortho_proj_override (float camera_distance)
412+ {
413+ gr_ortho_override_active = true ;
414+ gr_ortho_override_distance = camera_distance;
415+ }
416+
417+ void gr_deactivate_ortho_proj_override ()
418+ {
419+ gr_ortho_override_active = false ;
420+ gr_ortho_override_distance = 0 .0f ;
421+ }
0 commit comments