DEADSOFTWARE

gl: implement split screen
[d2df-sdl.git] / src / game / renders / opengl / r_render.pas
index 6e9b96c8a813d6a7abbc1bee72a90c6db064399a..8b67f060679935e743f31a0bea4daa6c279a2cda 100644 (file)
@@ -84,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_common, r_map
+    r_draw, r_textures, r_fonts, r_common, r_console, r_map
   ;
 
   type
@@ -135,6 +135,7 @@ 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;
@@ -148,6 +149,7 @@ implementation
       r_GUI_Free;
     {$ENDIF}
     r_Map_Free;
+    r_Console_Free;
     hudjet.Free;
     hudair.Free;
     hudkey[0].Free;
@@ -193,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
@@ -325,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
@@ -338,12 +336,18 @@ 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_Draw;
@@ -351,12 +355,14 @@ 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]);
 
@@ -368,7 +374,15 @@ implementation
       // 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
 
@@ -403,7 +417,7 @@ implementation
       end;
     {$ENDIF}
 
-    // TODO draw console
+    r_Console_Draw(false);
 
     // TODO draw holmes interface
 
@@ -483,6 +497,7 @@ implementation
 
   procedure r_Render_DrawLoading (force: Boolean);
   begin
+    // TODO draw loading screen
   end;
 
 end.