DEADSOFTWARE

gl: draw menu background
[d2df-sdl.git] / src / game / renders / opengl / r_render.pas
index be9192d8a0a8e0aeec87ba210fea2f61d9745f88..ec08bf13b4c4b2274e8902855850f8d8a462913c 100644 (file)
@@ -74,6 +74,9 @@ implementation
     {$ELSE}
       GL, GLEXT,
     {$ENDIF}
+    {$IFDEF ENABLE_MENU}
+      r_gui,
+    {$ENDIF}
     {$IFDEF ENABLE_SYSTEM}
       g_system,
     {$ENDIF}
@@ -81,7 +84,7 @@ implementation
     e_log, utils,
     g_game, g_options, g_console, g_player, g_weapons, g_language,
     g_net,
-    r_draw, r_textures, r_fonts, r_map
+    r_draw, r_textures, r_fonts, r_common, r_console, r_map
   ;
 
   type
@@ -92,11 +95,7 @@ implementation
     );
 
   var
-    menuBG: TGLTexture;
-
-    stdfont: TGLFont;
-    smallfont: TGLFont;
-    menufont: TGLFont;
+    BackgroundTexture: THereTexture;
 
     hud, hudbg: TGLTexture;
     hudhp: array [Boolean] of TGLTexture;
@@ -116,27 +115,14 @@ implementation
     r_Map_FreeTextures;
   end;
 
-  function r_Render_LoadFont (const name: AnsiString): TGLFont;
-    var info: TFontInfo; skiphack: Integer;
-  begin
-    result := nil;
-    if name = 'STD' then skiphack := 144 else skiphack := 0;
-    if r_Font_LoadInfoFromFile(GameWad + ':FONTS/' + name + 'TXT', info) then
-      result := r_Textures_LoadFontFromFile(GameWad + ':FONTS/' + name + 'FONT', info, skiphack, true);
-    if result = nil then
-      e_logwritefln('failed to load font %s', [name]);
-  end;
-
   procedure r_Render_Load;
     const
       WeapName: array [0..WP_LAST] of AnsiString = ('KASTET', 'SAW', 'PISTOL', 'SHOTGUN1', 'SHOTGUN2', 'MGUN', 'RLAUNCHER', 'PGUN', 'BFG', 'SPULEMET', 'FLAMETHROWER');
     var
       i: Integer;
   begin
-    menuBG := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/TITLE');
-    stdfont := r_Render_LoadFont('STD');
-    smallfont := r_Render_LoadFont('SMALL');
-    menufont := r_Render_LoadFont('MENU');
+    r_Common_Load;
+    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');
@@ -149,13 +135,21 @@ implementation
     hudkey[2] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYB');
     hudair := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/AIRBAR');
     hudjet := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/JETBAR');
+    r_Console_Load;
     r_Map_Load;
+    {$IFDEF ENABLE_MENU}
+      r_GUI_Load;
+    {$ENDIF}
   end;
 
   procedure r_Render_Free;
     var i: Integer;
   begin
+    {$IFDEF ENABLE_MENU}
+      r_GUI_Free;
+    {$ENDIF}
     r_Map_Free;
+    r_Console_Free;
     hudjet.Free;
     hudair.Free;
     hudkey[0].Free;
@@ -172,10 +166,8 @@ implementation
     hudhp[false].Free;
     hudbg.Free;
     hud.Free;
-    menufont.Free;
-    smallfont.Free;
-    stdfont.Free;
-    menuBG.Free;
+    r_Common_FreeThis(BackgroundTexture);
+    r_Common_Free;
   end;
 
 {$IFDEF ENABLE_SYSTEM}
@@ -203,31 +195,23 @@ implementation
       sys_EnableVSync(gVSync);
     {$ENDIF}
     r_Textures_Initialize;
+    r_Console_Initialize;
     r_Map_Initialize;
   end;
 
   procedure r_Render_Finalize;
   begin
     r_Map_Finalize;
+    r_Console_Finalize;
     r_Textures_Finalize;
   end;
 
   procedure r_Render_Update;
   begin
+    r_Console_Update;
     r_Map_Update;
   end;
 
-  procedure SetupMatrix;
-  begin
-    glViewport(0, 0, gScreenWidth, gScreenHeight);
-    glScissor(0, 0, gScreenWidth, gScreenHeight);
-    glMatrixMode(GL_PROJECTION);
-    glLoadIdentity;
-    glOrtho(0, gScreenWidth, gScreenHeight, 0, 0, 1);
-    glMatrixMode(GL_MODELVIEW);
-    glLoadIdentity;
-  end;
-
   procedure r_Render_GetBasePoint (x, y, w, h: Integer; p: TBasePoint; out xx, yy: Integer);
   begin
     case p of
@@ -335,7 +319,11 @@ implementation
   end;
 
   procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
+    var l, t, r, b: Integer;
   begin
+    r_Draw_GetRect(l, t, r, b);
+    r_Draw_SetRect(x, y, x + w, y + h);
+
     if p <> nil then
       r_Map_Draw(x, y, w, h, p.obj.x + PLAYER_RECT_CX, p.obj.y + PLAYER_RECT_CY, p)
     else
@@ -348,12 +336,36 @@ implementation
       if p.Spectator and p.NoRespawn then
         r_Render_DrawText(_lc[I_PLAYER_SPECT4], x div 2 + w div 2, y div 2 + h div 2, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
     end;
+
+    r_Draw_SetRect(l, t, r, b);
   end;
 
   procedure r_Render_DrawPlayerView (x, y, w, h: Integer; p: TPlayer);
+    var l, t, r, b: Integer;
   begin
+    r_Draw_GetRect(l, t, r, b);
+    r_Draw_SetRect(x, y, x + w, y + h);
     r_Render_DrawView(x, y, w - 196, h, p);
     r_Render_DrawHUDArea(x + w - 196, y, 196, h, p);
+    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;
@@ -361,24 +373,31 @@ implementation
     if gExit = EXIT_QUIT then
       exit;
 
-    SetupMatrix;
+    r_Draw_Setup(gScreenWidth, gScreenHeight);
 
     glClearColor(0.0, 0.0, 0.0, 0.0);
     glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
 
     glColor4ub(255, 255, 255, 255);
+    glEnable(GL_SCISSOR_TEST);
+    r_Draw_SetRect(0, 0, gScreenWidth, gScreenHeight);
 
     //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
-      r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, gPlayer1);
+      if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
+       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
+      else
+      begin
+        r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, gPlayer1);
+      end;
 
       // TODO draw holmes inspector
 
@@ -395,23 +414,74 @@ 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;
 
     {$IFDEF ENABLE_MENU}
       if g_ActiveWindow <> nil then
       begin
-        // TODO draw menu widgets
+        if gGameOn then
+          r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
+        r_GUI_Draw_Window(g_ActiveWindow);
       end;
     {$ENDIF}
 
-    // TODO draw console
+    r_Console_Draw(false);
 
     // TODO draw holmes interface
 
@@ -470,27 +540,28 @@ implementation
 {$IFDEF ENABLE_MENU}
   procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
   begin
-    w := 0; h := 0;
+    r_GUI_GetSize(ctrl, w, h);
   end;
 
   procedure r_Render_GetLogoSize (out w, h: Integer);
   begin
-    w := 0; h := 0;
+    r_GUI_GetLogoSize(w, h);
   end;
 
   procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
   begin
-    w := 0; h := 0;
+    r_GUI_GetMaxFontSize(BigFont, w, h);
   end;
 
   procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
   begin
-    w := 0; h := 0;
+    r_GUI_GetStringSize(BigFont, str, w, h);
   end;
 {$ENDIF}
 
   procedure r_Render_DrawLoading (force: Boolean);
   begin
+    // TODO draw loading screen
   end;
 
 end.