From 4dabb5d1f90f538c835ee72ca242171cb06d9dfa Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Sun, 19 Oct 2025 03:17:08 +0500 Subject: [PATCH] ref: gl: implement rotation for 2D --- ref/gl/gl_context.c | 7 ++----- ref/gl/gl_draw.c | 21 +++++++++++++++++++-- ref/gl/gl_local.h | 2 ++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/ref/gl/gl_context.c b/ref/gl/gl_context.c index db572995..53bf1235 100644 --- a/ref/gl/gl_context.c +++ b/ref/gl/gl_context.c @@ -365,11 +365,8 @@ static void GAME_EXPORT R_SetupSky( int *skyboxTextures ) static qboolean R_SetDisplayTransform( ref_screen_rotation_t rotate, int offset_x, int offset_y, float scale_x, float scale_y ) { qboolean ret = true; - if( rotate > 0 ) - { - gEngfuncs.Con_Printf("rotation transform not supported\n"); - ret = false; - } + + tr.rotation = rotate; if( offset_x || offset_y ) { diff --git a/ref/gl/gl_draw.c b/ref/gl/gl_draw.c index cf6b4c1d..4fa6b65c 100644 --- a/ref/gl/gl_draw.c +++ b/ref/gl/gl_draw.c @@ -215,10 +215,27 @@ void R_Set2DMode( qboolean enable ) return; // set 2D virtual screen size - pglViewport( 0, 0, gpGlobals->width, gpGlobals->height ); + switch( tr.rotation ) + { + case REF_ROTATE_CW: + pglViewport( 0, 0, gpGlobals->height, gpGlobals->width ); + Matrix4x4_CreateOrtho( projection_matrix, 0, gpGlobals->height, gpGlobals->width, 0, -99999, 99999 ); + Matrix4x4_ConcatRotate( projection_matrix, 90, 0, 0, 1 ); + Matrix4x4_ConcatTranslate( projection_matrix, 0, -gpGlobals->height, 0 ); + break; + case REF_ROTATE_CCW: + pglViewport( 0, 0, gpGlobals->height, gpGlobals->width ); + Matrix4x4_CreateOrtho( projection_matrix, 0, gpGlobals->height, gpGlobals->width, 0, -99999, 99999 ); + Matrix4x4_ConcatRotate( projection_matrix, -90, 0, 0, 1 ); + Matrix4x4_ConcatTranslate( projection_matrix, -gpGlobals->width, 0, 0 ); + break; + default: + pglViewport( 0, 0, gpGlobals->width, gpGlobals->height ); + Matrix4x4_CreateOrtho( projection_matrix, 0, gpGlobals->width, gpGlobals->height, 0, -99999, 99999 ); + break; + } pglMatrixMode( GL_PROJECTION ); - Matrix4x4_CreateOrtho( projection_matrix, 0, gpGlobals->width, gpGlobals->height, 0, -99999, 99999 ); GL_LoadMatrix( projection_matrix ); pglMatrixMode( GL_MODELVIEW ); diff --git a/ref/gl/gl_local.h b/ref/gl/gl_local.h index bb4ad5bc..95b4df8e 100644 --- a/ref/gl/gl_local.h +++ b/ref/gl/gl_local.h @@ -263,6 +263,8 @@ typedef struct uint *screengammatable; uint max_entities; + + ref_screen_rotation_t rotation; } gl_globals_t; typedef struct