From: DeaDDooMER Date: Mon, 13 Feb 2023 00:08:16 +0000 (+0300) Subject: gl: implement r_resolution_scale (without FBO) X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=0c447046675a6de0d4cfb88e3cfc31b885138ba1;p=d2df-sdl.git gl: implement r_resolution_scale (without FBO) --- diff --git a/src/game/renders/opengl/r_draw.pas b/src/game/renders/opengl/r_draw.pas index c839936..8442a2a 100644 --- a/src/game/renders/opengl/r_draw.pas +++ b/src/game/renders/opengl/r_draw.pas @@ -37,7 +37,7 @@ interface procedure r_Draw_Text (const text: AnsiString; x, y: Integer; r, g, b, a: Byte; f: TGLFont); procedure r_Draw_GetTextSize (const text: AnsiString; f: TGLFont; out w, h: Integer); - procedure r_Draw_Setup (w, h: Integer); + procedure r_Draw_Setup (sw, sh, gw, gh: Integer); procedure r_Draw_SetRect (l, t, r, b: Integer); procedure r_Draw_GetRect (out l, t, r, b: Integer); @@ -65,6 +65,7 @@ implementation var sl, st, sr, sb: Integer; ScreenWidth, ScreenHeight: Integer; + GameWidth, GameHeight: Integer; enableTexture2D: Boolean; curR, curG, curB, curA: Byte; @@ -90,21 +91,23 @@ implementation end; end; - procedure r_Draw_Setup (w, h: Integer); + procedure r_Draw_Setup (sw, sh, gw, gh: Integer); begin - ASSERT(w >= 0); - ASSERT(h >= 0); - ScreenWidth := w; - ScreenHeight := h; - glScissor(0, 0, w, h); - glViewport(0, 0, w, h); + ASSERT((sw >= 0) and (sh >= 0)); // screen/window size + ASSERT((gw >= 0) and (gh >= 0)); // virtual screen size + ScreenWidth := sw; + ScreenHeight := sh; + GameWidth := gw; + GameHeight := gh; + glScissor(0, 0, sw, sh); + glViewport(0, 0, sw, sh); glMatrixMode(GL_PROJECTION); glLoadIdentity; - glOrtho(0, w, h, 0, 0, 1); + glOrtho(0, gw, gh, 0, 0, 1); glMatrixMode(GL_MODELVIEW); glLoadIdentity; glEnable(GL_SCISSOR_TEST); - r_Draw_SetRect(0, 0, w - 1, h - 1); + r_Draw_SetRect(0, 0, gw - 1, gh - 1); end; procedure DrawQuad (x, y, w, h: Integer); @@ -396,13 +399,15 @@ implementation end; procedure r_Draw_SetRect (l, t, r, b: Integer); - var w, h: Integer; + var x, y, w, h: Integer; begin ASSERT(l <= r); ASSERT(t <= b); - w := r - l + 1; - h := b - t + 1; - glScissor(l, ScreenHeight - h - t, w, h); + x := l * ScreenWidth div GameWidth; + y := t * ScreenHeight div GameHeight; + w := (r - l + 1) * ScreenWidth div GameWidth; + h := (b - t + 1) * ScreenHeight div GameHeight; + glScissor(x, ScreenHeight - h - y, w, h); sl := l; st := t; sr := r; sb := b; end; diff --git a/src/game/renders/opengl/r_loadscreen.pas b/src/game/renders/opengl/r_loadscreen.pas index 31d2934..2786eb3 100644 --- a/src/game/renders/opengl/r_loadscreen.pas +++ b/src/game/renders/opengl/r_loadscreen.pas @@ -142,7 +142,7 @@ implementation xx := gScreenWidth div 3; yy := gScreenHeight div 3; hh := gScreenHeight - yy - 96; - r_Draw_Setup(gScreenWidth, gScreenHeight); + r_Draw_Setup(gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); r_Common_DrawBackground(GameWad + ':TEXTURES/INTER'); diff --git a/src/game/renders/opengl/r_render.pas b/src/game/renders/opengl/r_render.pas index 5a15b28..369fa88 100644 --- a/src/game/renders/opengl/r_render.pas +++ b/src/game/renders/opengl/r_render.pas @@ -1056,7 +1056,7 @@ implementation FPSTime := time; end; - r_Draw_Setup(gScreenWidth, gScreenHeight); + r_Draw_Setup(gWinSizeX, gWinSizeY, gScreenWidth, gScreenHeight); glClearColor(0.0, 0.0, 0.0, 0.0); glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT); @@ -1248,8 +1248,8 @@ implementation gWinSizeY := h; gRC_Width := w; gRC_Height := h; - gScreenWidth := w; - gScreenHeight := h; + gScreenWidth := Round(w / r_pixel_scale); + gScreenHeight := Round(h / r_pixel_scale); end; procedure r_Render_Apply;