From: DeaDDooMER Date: Mon, 18 Jul 2022 15:02:34 +0000 (+0300) Subject: gl: draw menu background X-Git-Url: http://deadsoftware.ru/gitweb?p=d2df-sdl.git;a=commitdiff_plain;h=a0269440c6b9e8f1f0f578f26864804f9a412b13 gl: draw menu background --- diff --git a/src/game/renders/opengl/r_common.pas b/src/game/renders/opengl/r_common.pas index ba934c5..61d0343 100644 --- a/src/game/renders/opengl/r_common.pas +++ b/src/game/renders/opengl/r_common.pas @@ -19,11 +19,22 @@ interface uses r_textures; + type + THereTexture = record + name: AnsiString; + id: TGLTexture; + end; + var stdfont: TGLFont; smallfont: TGLFont; menufont: TGLFont; + function r_Common_LoadThis (const name: AnsiString; var here: THereTexture): Boolean; + procedure r_Common_FreeThis (var here: THereTexture); + + procedure r_Common_CalcAspect (ow, oh, nw, nh: LongInt; horizontal: Boolean; out ww, hh: LongInt); + procedure r_Common_Load; procedure r_Common_Free; @@ -31,6 +42,41 @@ implementation uses e_log, r_fonts, g_options; + procedure r_Common_FreeThis (var here: THereTexture); + begin + here.name := ''; + if here.id <> nil then + here.id.Free; + here.id := nil; + end; + + function r_Common_LoadThis (const name: AnsiString; var here: THereTexture): Boolean; + begin + if name <> here.name then + r_Common_FreeThis(here); + if (name <> '') and (here.name <> name) then + here.id := r_Textures_LoadFromFile(name); + + result := here.id <> nil; + + if result then + here.name := name; + end; + + procedure r_Common_CalcAspect (ow, oh, nw, nh: LongInt; horizontal: Boolean; out ww, hh: LongInt); + begin + if horizontal then + begin + ww := nw; + hh := nw * oh div ow; + end + else + begin + ww := nh * ow div oh; + hh := nh; + end; + end; + function r_Common_LoadFont (const name: AnsiString): TGLFont; var info: TFontInfo; skiphack: Integer; begin diff --git a/src/game/renders/opengl/r_gui.pas b/src/game/renders/opengl/r_gui.pas index 7016db9..0619108 100644 --- a/src/game/renders/opengl/r_gui.pas +++ b/src/game/renders/opengl/r_gui.pas @@ -42,12 +42,6 @@ implementation const EDIT_CURSORLEN = 10; - type - THereTexture = record - name: AnsiString; - id: TGLTexture; - end; - var Box: Array [0..8] of TGLTexture; MarkerID: array [Boolean] of TGLTexture; @@ -63,22 +57,6 @@ implementation Background: THereTexture; ImageControl: THereTexture; - procedure r_GUI_FreeThis (var here: THereTexture); - begin - here.name := ''; - if here.id <> nil then - here.id.Free; - here.id := nil; - end; - - function r_GUI_LoadThis (const name: AnsiString; var here: THereTexture): Boolean; - begin - r_GUI_FreeThis(here); - if (name <> '') and (here.name <> name) then - here.id := r_Textures_LoadFromFile(name); - result := here.id <> nil; - end; - procedure r_GUI_Load; var i: Integer; begin @@ -140,8 +118,8 @@ implementation LogoTex.Free; nopic.Free; - r_GUI_FreeThis(Background); - r_GUI_FreeThis(ImageControl); + r_Common_FreeThis(Background); + r_Common_FreeThis(ImageControl); end; procedure r_GUI_GetMaxFontSize (BigFont: Boolean; out w, h: Integer); @@ -412,7 +390,7 @@ implementation begin pic := nopic; if ctrl.ImageRes <> '' then - if r_GUI_LoadThis(ctrl.ImageRes, ImageControl) then + if r_Common_LoadThis(ctrl.ImageRes, ImageControl) then pic := ImageControl.id; if pic <> nil then r_Draw_Texture(pic, ctrl.x, ctrl.y, pic.width, pic.height, false, 255, 255, 255, 255, false); @@ -573,7 +551,7 @@ implementation begin // Here goes code duplication from g_game.pas:DrawMenuBackground() if win.BackTexture <> '' then - if r_GUI_LoadThis(win.BackTexture, Background) then + if r_Common_LoadThis(win.BackTexture, Background) then begin r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 255); tw := Background.id.width; diff --git a/src/game/renders/opengl/r_map.pas b/src/game/renders/opengl/r_map.pas index f010f29..812fd85 100644 --- a/src/game/renders/opengl/r_map.pas +++ b/src/game/renders/opengl/r_map.pas @@ -1177,20 +1177,6 @@ implementation end; {$ENDIF} - procedure r_Map_CalcAspect (ow, oh, nw, nh: LongInt; horizontal: Boolean; out ww, hh: LongInt); - begin - if horizontal then - begin - ww := nw; - hh := nw * oh div ow; - end - else - begin - ww := nh * ow div oh; - hh := nh; - end; - end; - procedure r_Map_CalcSkyParallax (cx, cy, vw, vh, sw, sh, mw, mh: LongInt; out x, y, w, h: LongInt); const factor = 120; (* size ratio between view and sky (120%) *) @@ -1200,7 +1186,7 @@ implementation begin msw := vw * factor div 100; msh := vh * factor div 100; - r_Map_CalcAspect(sw, sh, msw, msh, (sw / sh) <= (msw / msh), w, h); + r_Common_CalcAspect(sw, sh, msw, msh, (sw / sh) <= (msw / msh), w, h); (* calc x parallax or sky center on speed limit *) mvw := MAX(1, mw - vw); diff --git a/src/game/renders/opengl/r_render.pas b/src/game/renders/opengl/r_render.pas index 8b67f06..ec08bf1 100644 --- a/src/game/renders/opengl/r_render.pas +++ b/src/game/renders/opengl/r_render.pas @@ -95,7 +95,7 @@ implementation ); var - menuBG: TGLTexture; + BackgroundTexture: THereTexture; hud, hudbg: TGLTexture; hudhp: array [Boolean] of TGLTexture; @@ -122,7 +122,7 @@ implementation i: Integer; begin r_Common_Load; - menuBG := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/TITLE'); + BackgroundTexture := DEFAULT(THereTexture); hud := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUD'); hudbg := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUDBG'); hudhp[false] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/MED2'); @@ -166,7 +166,7 @@ implementation hudhp[false].Free; hudbg.Free; hud.Free; - menuBG.Free; + r_Common_FreeThis(BackgroundTexture); r_Common_Free; end; @@ -350,6 +350,24 @@ implementation r_Draw_SetRect(l, t, r, b); end; + procedure r_Render_DrawBackgroundImage (img: TGLTexture); + var fw, w, h: LongInt; + begin + if img <> nil then + begin + img := BackgroundTexture.id; + fw := img.width * 4 div 3; // fix aspect 4:3 + r_Common_CalcAspect(fw, img.height, gScreenWidth, gScreenHeight, false, w, h); + r_Draw_Texture(img, gScreenWidth div 2 - w div 2, 0, w, h, false, 255, 255, 255, 255, false); + end + end; + + procedure r_Render_DrawBackground (const name: AnsiString); + begin + if r_Common_LoadThis(name, BackgroundTexture) then + r_Render_DrawBackgroundImage(BackgroundTexture.id) + end; + procedure r_Render_Draw; begin if gExit = EXIT_QUIT then @@ -366,16 +384,13 @@ implementation //e_LogWritefln('r_render_draw: %sx%s', [gScreenWidth, gScreenHeight]); - if gGameOn or (gState = STATE_FOLD) then + if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then begin - // TODO setup player view // TODO setup sectator mode // TODO setup player hear point - // TODO setup player view siz - // TODO draw player view + setup screen coords if (gPlayer1 <> nil) and (gPlayer2 <> nil) then - begin + begin r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, gPlayer1); r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, gPlayer2); end @@ -399,12 +414,61 @@ implementation if not gGameOn then begin case gState of - STATE_MENU: ; // TODO draw menu bg - STATE_FOLD: ; - STATE_INTERCUSTOM: ; - STATE_INTERSINGLE: ; - STATE_ENDPIC: ; - STATE_SLIST: ; + STATE_NONE: (* do nothing *) ; + STATE_MENU: r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE'); + STATE_FOLD: + begin + if EndingGameCounter > 0 then + r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255)); + end; + STATE_INTERCUSTOM: + begin + if gLastMap and (gGameSettings.GameMode = GM_COOP) then + if EndPicPath <> '' then + r_Render_DrawBackground(EndPicPath) + else + r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]) + else + r_Render_DrawBackground(GameWad + ':TEXTURES/INTER'); + // TODO draw custom stata + {$IFDEF ENABLE_MENU} + if g_ActiveWindow <> nil then + r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105); + {$ENDIF} + end; + STATE_INTERSINGLE, STATE_INTERTEXT, STATE_INTERPIC: + begin + if EndingGameCounter > 0 then + begin + r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255)); + end + else + begin + r_Render_DrawBackground(GameWad + ':TEXTURES/INTER'); + // TODO darw single stats + {$IFDEF ENABLE_MENU} + if g_ActiveWindow <> nil then + r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105); + {$ENDIF} + end; + end; + STATE_ENDPIC: + begin + if EndPicPath <> '' then + r_Render_DrawBackground(EndPicPath) + else + r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]); + {$IFDEF ENABLE_MENU} + if g_ActiveWindow <> nil then + r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105); + {$ENDIF} + end; + STATE_SLIST: + begin + r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE'); + r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105); + // TODO draw serverlist + end; end; end;