Skip to content

Commit 7fb789f

Browse files
committed
Fix gr_end_2d_matrix viewport for render-to-texture
`gr_set_proj_matrix` already branches on rendering_to_texture to choose top-left (RTT) vs bottom-left (screen) viewport origin. `gr_end_2d_matrix` should match, but it unconditionally used the bottom-left formula. Add the same `rendering_to_texture` branch so the viewport is restored correctly when rendering to a texture.
1 parent 0186e87 commit 7fb789f

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

code/graphics/matrix.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,11 @@ void gr_end_2d_matrix()
272272
Assert( htl_2d_matrix_depth == 1 );
273273

274274
// reset viewport to what it was originally set to by the proj matrix
275-
gr_set_viewport(gr_screen.offset_x, (gr_screen.max_h - gr_screen.offset_y - gr_screen.clip_height), gr_screen.clip_width, gr_screen.clip_height);
275+
if (gr_screen.rendering_to_texture != -1) {
276+
gr_set_viewport(gr_screen.offset_x, gr_screen.offset_y, gr_screen.clip_width, gr_screen.clip_height);
277+
} else {
278+
gr_set_viewport(gr_screen.offset_x, (gr_screen.max_h - gr_screen.offset_y - gr_screen.clip_height), gr_screen.clip_width, gr_screen.clip_height);
279+
}
276280

277281
gr_projection_matrix = gr_last_projection_matrix;
278282

0 commit comments

Comments
 (0)