DEADSOFTWARE

aff2252b8c6c2d00ab240100249e2480a4d9c377
[d2df-sdl.git] / src / game / renders / opengl / r_render.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../../../shared/a_modes.inc}
16 unit r_render;
18 interface
20 uses
21 {$IFDEF ENABLE_MENU}
22 g_gui,
23 {$ENDIF}
24 g_base // TRectWH
25 ;
27 (* render startup *)
28 procedure r_Render_Initialize;
29 procedure r_Render_Finalize;
31 (* load globally used textures *)
32 procedure r_Render_Load;
33 procedure r_Render_Free;
35 (* load map specific textures *)
36 procedure r_Render_LoadTextures;
37 procedure r_Render_FreeTextures;
39 procedure r_Render_Update;
40 procedure r_Render_Draw;
42 procedure r_Render_Resize (w, h: Integer);
43 procedure r_Render_Apply;
45 function r_Render_WriteScreenShot (filename: String): Boolean;
47 {$IFDEF ENABLE_GIBS}
48 function r_Render_GetGibRect (m, id: Integer): TRectWH;
49 {$ENDIF}
51 {$IFDEF ENABLE_GFX}
52 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
53 {$ENDIF}
55 {$IFDEF ENABLE_TOUCH}
56 // touch screen button location and size
57 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
58 {$ENDIF}
60 {$IFDEF ENABLE_MENU}
61 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
62 procedure r_Render_GetLogoSize (out w, h: Integer);
63 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
64 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
65 {$ENDIF}
67 procedure r_Render_DrawLoading (force: Boolean); // !!! remove it
69 implementation
71 uses
72 {$IFDEF USE_GLES1}
73 GLES11,
74 {$ELSE}
75 GL, GLEXT,
76 {$ENDIF}
77 {$IFDEF ENABLE_MENU}
78 r_gui,
79 {$ENDIF}
80 {$IFDEF ENABLE_SYSTEM}
81 g_system,
82 {$ENDIF}
83 SysUtils, Classes, Math,
84 e_log, utils,
85 g_basic,
86 g_game, g_options, g_console, g_player, g_weapons, g_language,
87 g_net, g_netmaster,
88 r_draw, r_textures, r_fonts, r_common, r_console, r_map
89 ;
91 type
92 TBasePoint = (
93 BP_LEFTUP, BP_UP, BP_RIGHTUP,
94 BP_LEFT, BP_CENTER, BP_RIGHT,
95 BP_LEFTDOWN, BP_DOWN, BP_RIGHTDOWN
96 );
98 var
99 BackgroundTexture: THereTexture;
101 hud, hudbg: TGLTexture;
102 hudhp: array [Boolean] of TGLTexture;
103 hudap: TGLTexture;
104 hudwp: array [0..WP_LAST] of TGLTexture;
105 hudkey: array [0..2] of TGLTexture;
106 hudair: TGLTexture;
107 hudjet: TGLTexture;
109 procedure r_Render_LoadTextures;
110 begin
111 r_Map_LoadTextures;
112 end;
114 procedure r_Render_FreeTextures;
115 begin
116 r_Map_FreeTextures;
117 end;
119 procedure r_Render_Load;
120 const
121 WeapName: array [0..WP_LAST] of AnsiString = ('KASTET', 'SAW', 'PISTOL', 'SHOTGUN1', 'SHOTGUN2', 'MGUN', 'RLAUNCHER', 'PGUN', 'BFG', 'SPULEMET', 'FLAMETHROWER');
122 var
123 i: Integer;
124 begin
125 r_Common_Load;
126 BackgroundTexture := DEFAULT(THereTexture);
127 hud := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUD');
128 hudbg := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUDBG');
129 hudhp[false] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/MED2');
130 hudhp[true] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/BMED');
131 hudap := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/ARMORHUD');
132 for i := 0 to WP_LAST do
133 hudwp[i] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/' + WeapName[i]);
134 hudkey[0] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYR');
135 hudkey[1] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYG');
136 hudkey[2] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYB');
137 hudair := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/AIRBAR');
138 hudjet := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/JETBAR');
139 r_Console_Load;
140 r_Map_Load;
141 {$IFDEF ENABLE_MENU}
142 r_GUI_Load;
143 {$ENDIF}
144 end;
146 procedure r_Render_Free;
147 var i: Integer;
148 begin
149 {$IFDEF ENABLE_MENU}
150 r_GUI_Free;
151 {$ENDIF}
152 r_Map_Free;
153 r_Console_Free;
154 hudjet.Free;
155 hudair.Free;
156 hudkey[0].Free;
157 hudkey[1].Free;
158 hudkey[2].Free;
159 for i := 0 to WP_LAST do
160 begin
161 if hudwp[i] <> nil then
162 hudwp[i].Free;
163 hudwp[i] := nil;
164 end;
165 hudap.Free;
166 hudhp[true].Free;
167 hudhp[false].Free;
168 hudbg.Free;
169 hud.Free;
170 r_Common_FreeThis(BackgroundTexture);
171 r_Common_Free;
172 end;
174 {$IFDEF ENABLE_SYSTEM}
175 function GetInfo (): TGLDisplayInfo;
176 var info: TGLDisplayInfo;
177 begin
178 info := Default(TGLDisplayInfo);
179 info.w := Max(1, gRC_Width);
180 info.h := Max(1, gRC_Height);
181 info.bpp := Max(1, gBPP);
182 info.fullscreen := gRC_FullScreen;
183 info.maximized := gRC_Maximized;
184 info.major := 1;
185 info.minor := 1;
186 info.profile := TGLProfile.Compat;
187 result := info;
188 end;
189 {$ENDIF}
191 procedure r_Render_Initialize;
192 begin
193 {$IFDEF ENABLE_SYSTEM}
194 if sys_SetDisplayModeGL(GetInfo()) = False then
195 raise Exception.Create('Failed to set videomode on startup.');
196 sys_EnableVSync(gVSync);
197 {$ENDIF}
198 r_Textures_Initialize;
199 r_Console_Initialize;
200 r_Map_Initialize;
201 end;
203 procedure r_Render_Finalize;
204 begin
205 r_Map_Finalize;
206 r_Console_Finalize;
207 r_Textures_Finalize;
208 end;
210 procedure r_Render_Update;
211 begin
212 r_Console_Update;
213 r_Map_Update;
214 end;
216 procedure r_Render_GetBasePoint (x, y, w, h: Integer; p: TBasePoint; out xx, yy: Integer);
217 begin
218 case p of
219 TBasePoint.BP_LEFTUP, TBasePoint.BP_LEFT, TBasePoint.BP_LEFTDOWN: xx := x;
220 TBasePoint.BP_UP, TBasePoint.BP_CENTER, TBasePoint.BP_DOWN: xx := x - w div 2;
221 TBasePoint.BP_RIGHTUP, TBasePoint.BP_RIGHT, TBasePoint.BP_RIGHTDOWN: xx := x - w;
222 end;
223 case p of
224 TBasePoint.BP_LEFTUP, TBasePoint.BP_UP, TBasePoint.BP_RIGHTUP: yy := y;
225 TBasePoint.BP_LEFT, TBasePoint.BP_CENTER, TBasePoint.BP_RIGHT: yy := y - h div 2;
226 TBasePoint.BP_LEFTDOWN, TBasePoint.BP_DOWN, TBasePoint.BP_RIGHTDOWN: yy := y - h;
227 end;
228 end;
230 procedure r_Render_DrawText (const text: AnsiString; x, y: Integer; r, g, b, a: Byte; f: TGLFont; p: TBasePoint);
231 var w, h: Integer;
232 begin
233 if p <> TBasePoint.BP_LEFTUP then
234 begin
235 r_Draw_GetTextSize(text, f, w, h);
236 r_Render_GetBasePoint(x, y, w, h, p, x, y);
237 end;
238 r_Draw_Text(text, x, y, r, g, b, a, f);
239 end;
241 procedure r_Render_DrawTexture (img: TGLTexture; x, y, w, h: Integer; p: TBasePoint);
242 begin
243 r_Render_GetBasePoint(x, y, w, h, p, x, y);
244 r_Draw_TextureRepeat(img, x, y, w, h, false, 255, 255, 255, 255, false);
245 end;
247 procedure r_Render_DrawHUD (x, y: Integer; p: TPlayer);
248 var t: TGLTexture; s: AnsiString;
249 begin
250 ASSERT(p <> nil);
252 // hud area is 196 x 240 pixels
253 r_Render_DrawTexture(hud, x, y, hud.width, hud.height, TBasePoint.BP_LEFTUP);
254 r_Render_DrawText(p.name, x + 98, y + 16, 255, 0, 0, 255, smallfont, TBasePoint.BP_CENTER);
256 t := hudhp[R_BERSERK in p.FRulez];
257 r_Render_DrawTexture(t, x + 51, y + 61, t.width, t.height, TBasePoint.BP_CENTER);
258 r_Render_DrawTexture(hudap, x + 50, y + 85, hudap.width, hudap.height, TBasePoint.BP_CENTER);
260 r_Render_DrawText(IntToStr(MAX(0, p.health)), x + 174, y + 56, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
261 r_Render_DrawText(IntToStr(MAX(0, p.armor)), x + 174, y + 84, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
263 case p.CurrWeap of
264 WEAPON_KASTET, WEAPON_SAW: s := '--';
265 else s := IntToStr(p.GetAmmoByWeapon(p.CurrWeap));
266 end;
267 r_Render_DrawText(s, x + 174, y + 174, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
269 if p.CurrWeap <= WP_LAST then
270 begin
271 t := hudwp[p.CurrWeap];
272 r_Render_DrawTexture(t, x + 18, y + 160, t.width, t.height, TBasePoint.BP_LEFTUP);
273 end;
275 if R_KEY_RED in p.FRulez then
276 r_Render_DrawTexture(hudkey[0], x + 76, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
277 if R_KEY_GREEN in p.FRulez then
278 r_Render_DrawTexture(hudkey[1], x + 93, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
279 if R_KEY_BLUE in p.FRulez then
280 r_Render_DrawTexture(hudkey[2], x + 110, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
282 if p.JetFuel > 0 then
283 begin
284 r_Render_DrawTexture(hudair, x, y + 116, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
285 if p.air > 0 then
286 r_Draw_FillRect(x + 14, y + 116 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 116 + 4 + 4, 0, 0, 196, 255);
287 r_Render_DrawTexture(hudjet, x, y + 126, hudjet.width, hudjet.height, TBasePoint.BP_LEFTUP);
288 r_Draw_FillRect(x + 14, y + 126 + 4, x + 14 + 168 * p.JetFuel div JET_MAX, y + 126 + 4 + 4, 208, 0, 0, 255);
289 end
290 else
291 begin
292 r_Render_DrawTexture(hudair, x, y + 124, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
293 if p.air > 0 then
294 r_Draw_FillRect(x + 14, y + 124 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 124 + 4 + 4, 0, 0, 196, 255);
295 end;
296 end;
298 procedure r_Render_DrawHUDArea (x, y, w, h: Integer; p: TPlayer);
299 var s: AnsiString;
300 begin
301 r_Render_DrawTexture(hudbg, x, y, w, h, TBasePoint.BP_LEFTUP);
303 if p <> nil then
304 r_Render_DrawHUD(x + w - 196 + 2, y, p);
306 if gShowPing and g_Game_IsClient then
307 begin
308 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
309 r_Render_DrawText(s, x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
310 end;
312 if p.Spectator then
313 begin
314 r_Render_DrawText(_lc[I_PLAYER_SPECT], x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
315 r_Render_DrawText(_lc[I_PLAYER_SPECT2], x + 4, y + 258, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
316 r_Render_DrawText(_lc[I_PLAYER_SPECT1], x + 4, y + 274, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
317 if p.NoRespawn then
318 r_Render_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
319 end;
320 end;
322 procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
323 var l, t, r, b: Integer;
324 begin
325 r_Draw_GetRect(l, t, r, b);
326 r_Draw_SetRect(x, y, x + w, y + h);
328 if p <> nil then
329 r_Map_Draw(x, y, w, h, p.obj.x + PLAYER_RECT_CX, p.obj.y + PLAYER_RECT_CY, p)
330 else
331 r_Map_Draw(x, y, w, h, 0, 0, nil);
333 // TODO draw stats
335 if p <> nil then
336 begin
337 if p.Spectator and p.NoRespawn then
338 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);
339 end;
341 r_Draw_SetRect(l, t, r, b);
342 end;
344 procedure r_Render_DrawPlayerView (x, y, w, h: Integer; p: TPlayer);
345 var l, t, r, b: Integer;
346 begin
347 r_Draw_GetRect(l, t, r, b);
348 r_Draw_SetRect(x, y, x + w, y + h);
349 r_Render_DrawView(x, y, w - 196, h, p);
350 r_Render_DrawHUDArea(x + w - 196, y, 196, h, p);
351 r_Draw_SetRect(l, t, r, b);
352 end;
354 procedure r_Render_DrawBackgroundImage (img: TGLTexture);
355 var fw, w, h: LongInt;
356 begin
357 if img <> nil then
358 begin
359 img := BackgroundTexture.id;
360 fw := img.width * 4 div 3; // fix aspect 4:3
361 r_Common_CalcAspect(fw, img.height, gScreenWidth, gScreenHeight, false, w, h);
362 r_Draw_Texture(img, gScreenWidth div 2 - w div 2, 0, w, h, false, 255, 255, 255, 255, false);
363 end
364 end;
366 procedure r_Render_DrawBackground (const name: AnsiString);
367 begin
368 if r_Common_LoadThis(name, BackgroundTexture) then
369 r_Render_DrawBackgroundImage(BackgroundTexture.id)
370 end;
372 procedure r_Render_DrawServerList (var SL: TNetServerList; var ST: TNetServerTable);
373 var ip: AnsiString; ww, hh, cw, ch, mw, mh, motdh, scrx, scry, i, mx, y: Integer; msg: SSArray; Srv: TNetServer;
374 begin
375 scrx := gScreenWidth div 2;
376 scry := gScreenHeight div 2;
378 r_Draw_GetTextSize(_lc[I_NET_SLIST], menufont, ww, hh);
379 r_Render_DrawText(_lc[I_NET_SLIST], gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
381 r_Draw_GetTextSize('W', stdfont, cw, ch);
382 motdh := gScreenHeight - 49 - ch * b_Text_LineCount(slMOTD);
384 r_Draw_FillRect(16, 64, gScreenWidth - 16, motdh, 64, 64, 64, 145);
385 r_Draw_Rect(16, 64, gScreenWidth - 16, motdh, 255, 127, 0, 255);
387 r_Render_DrawText(_lc[I_NET_SLIST_HELP], gScreenWidth div 2, gScreenHeight - 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
389 if slMOTD <> '' then
390 begin
391 r_Draw_FillRect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 64, 64, 64, 110);
392 r_Draw_Rect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 255, 127, 0, 255);
393 msg := Parse2(slMOTD, #10);
394 for i := 0 to High(msg) do
395 r_Render_DrawText(msg[i], 20, motdh + 3 + ch * i, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
396 end;
398 if not slReadUrgent and (slUrgent <> '') then
399 begin
400 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
401 r_Draw_FillRect(scrx - 256, scry - 60, scrx + 256, scry + 60, 64, 64, 64, 127);
402 r_Draw_Rect(scrx - 256, scry - 60, scrx + 256, scry + 60, 255, 127, 0, 255);
403 r_Draw_FillRect(scrx - 256, scry - 40, scrx + 256, scry - 40, 255, 127, 0, 255);
404 r_Render_DrawText(_lc[I_NET_SLIST_URGENT], scrx, scry - 58, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
405 msg := Parse2(slUrgent, #10);
406 for i := 0 to High(msg) do
407 r_Render_DrawText(msg[i], scrx - 253, scry - 38 + ch * i, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
408 r_Render_DrawText(_lc[I_NET_SLIST_URGENT_CONT], scrx, scry + 41, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
409 r_Draw_FillRect(scrx - 256, scry + 40, scrx + 256, scry + 40, 255, 127, 0, 255);
410 end
411 else if SL = nil then
412 begin
413 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
414 r_Draw_Rect(scrx - 192, scry - 10, scrx + 192, scry + 11, 255, 127, 0, 255);
415 r_Render_DrawText(slWaitStr, scrx, scry, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
416 end
417 else
418 begin
419 y := 90;
420 if slSelection < Length(ST) then
421 begin
422 sy := y + 42 * slSelection - 4;
423 Srv := GetServerFromTable(slSelection, SL, ST);
424 ip := _lc[I_NET_ADDRESS] + ' ' + Srv.IP + ':' + IntToStr(Srv.Port);
425 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ';
426 if Srv.Password then ip := ip + _lc[I_MENU_YES] else ip := ip +_lc[I_MENU_NO];
427 end;
429 mw := gScreenWidth - 188;
430 mx := 16 + mw;
432 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 255);
433 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205, 255);
434 r_Draw_FillRect(16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255, 255);
436 r_Draw_FillRect(16, 85, gScreenWidth - 16, 85, 255, 127, 0, 255);
437 r_Draw_FillRect(16, motdh - 20, gScreenWidth - 16, motdh - 20, 255, 127, 0, 255);
439 r_Draw_FillRect(mx - 70, 64, mx - 70, motdh, 255, 127, 0, 255);
440 r_Draw_FillRect(mx, 64, mx, motdh - 20, 255, 127, 0, 255);
441 r_Draw_FillRect(mx + 52, 64, mx + 52, motdh - 20, 255, 127, 0, 255);
442 r_Draw_FillRect(mx + 104, 64, mx + 104, motdh - 20, 255, 127, 0, 255);
444 r_Render_DrawText('NAME/MAP', 18, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
445 r_Render_DrawText('PING', mx - 68, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
446 r_Render_DrawText('MODE', mx + 2, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
447 r_Render_DrawText('PLRS', mx + 54, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
448 r_Render_DrawText('VER', mx + 106, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
450 for i := 0 to High(ST) do
451 begin
452 Srv := GetServerFromTable(i, SL, ST);
453 r_Render_DrawText(Srv.Name, 18, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
454 r_Render_DrawText(Srv.Map, 18, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
456 if Srv.Ping = 0 then
457 r_Render_DrawText('<1' + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
458 else if (Srv.Ping >= 0) and (Srv.Ping <= 999) then
459 r_Render_DrawText(IntToStr(Srv.Ping) + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
460 else
461 r_Render_DrawText(_lc[I_NET_SLIST_NO_ACCESS], mx - 68, y, 255, 0, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
462 if Length(ST[I].Indices) > 1 then
463 r_Render_DrawText('<' + IntToStr(Length(ST[I].Indices)) + '>', mx - 68, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
465 r_Render_DrawText(g_Game_ModeToText(Srv.GameMode), mx + 2, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
467 r_Render_DrawText(IntToStr(Srv.Players) + '/' + IntToStr(Srv.MaxPlayers), mx + 54, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
468 r_Render_DrawText(IntToStr(Srv.LocalPl) + '+' + IntToStr(Srv.Bots), mx + 54, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
470 r_Render_DrawText(IntToStr(Srv.Protocol), mx + 106, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
472 y := y + 42;
473 end;
475 r_Render_DrawText(ip, 20, motdh - 20 + 3, 205, 205, 205, 255, stdfont, TBasePoint.BP_LEFTUP);
476 r_Render_DrawText(IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS], gScreenWidth - 48, motdh - 20 + 3, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
477 end;
478 end;
480 procedure r_Render_Draw;
481 begin
482 if gExit = EXIT_QUIT then
483 exit;
485 r_Draw_Setup(gScreenWidth, gScreenHeight);
487 glClearColor(0.0, 0.0, 0.0, 0.0);
488 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
490 glColor4ub(255, 255, 255, 255);
491 glEnable(GL_SCISSOR_TEST);
492 r_Draw_SetRect(0, 0, gScreenWidth, gScreenHeight);
494 //e_LogWritefln('r_render_draw: %sx%s', [gScreenWidth, gScreenHeight]);
496 if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then
497 begin
498 // TODO setup sectator mode
499 // TODO setup player hear point
501 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
502 begin
503 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, gPlayer1);
504 r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, gPlayer2);
505 end
506 else
507 begin
508 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, gPlayer1);
509 end;
511 // TODO draw holmes inspector
513 // TODO draw messages
514 // TODO draw stats (?)
515 // TODO draw spectator hud
516 end;
518 if gPauseMain and gGameOn {$IFDEF ENABLE_MENU}and (g_ActiveWindow = nil){$ENDIF} then
519 begin
520 // TODO draw pause screen
521 end;
523 if not gGameOn then
524 begin
525 case gState of
526 STATE_NONE: (* do nothing *) ;
527 STATE_MENU: r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
528 STATE_FOLD:
529 begin
530 if EndingGameCounter > 0 then
531 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
532 end;
533 STATE_INTERCUSTOM:
534 begin
535 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
536 if EndPicPath <> '' then
537 r_Render_DrawBackground(EndPicPath)
538 else
539 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC])
540 else
541 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
542 // TODO draw custom stata
543 {$IFDEF ENABLE_MENU}
544 if g_ActiveWindow <> nil then
545 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
546 {$ENDIF}
547 end;
548 STATE_INTERSINGLE, STATE_INTERTEXT, STATE_INTERPIC:
549 begin
550 if EndingGameCounter > 0 then
551 begin
552 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
553 end
554 else
555 begin
556 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
557 // TODO darw single stats
558 {$IFDEF ENABLE_MENU}
559 if g_ActiveWindow <> nil then
560 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
561 {$ENDIF}
562 end;
563 end;
564 STATE_ENDPIC:
565 begin
566 if EndPicPath <> '' then
567 r_Render_DrawBackground(EndPicPath)
568 else
569 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]);
570 {$IFDEF ENABLE_MENU}
571 if g_ActiveWindow <> nil then
572 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
573 {$ENDIF}
574 end;
575 STATE_SLIST:
576 begin
577 r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
578 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
579 r_Render_DrawServerList(slCurrent, slTable);
580 end;
581 end;
582 end;
584 {$IFDEF ENABLE_MENU}
585 if g_ActiveWindow <> nil then
586 begin
587 if gGameOn then
588 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
589 r_GUI_Draw_Window(g_ActiveWindow);
590 end;
591 {$ENDIF}
593 r_Console_Draw(false);
595 // TODO draw holmes interface
597 glFlush();
598 glFinish();
599 sys_Repaint;
600 end;
602 procedure r_Render_Resize (w, h: Integer);
603 begin
604 gWinSizeX := w;
605 gWinSizeY := h;
606 gRC_Width := w;
607 gRC_Height := h;
608 gScreenWidth := w;
609 gScreenHeight := h;
610 end;
612 procedure r_Render_Apply;
613 begin
614 {$IFDEF ENABLE_SYSTEM}
615 if sys_SetDisplayModeGL(GetInfo()) then
616 e_LogWriteln('resolution changed')
617 else
618 e_LogWriteln('resolution not changed');
619 sys_EnableVSync(gVSync)
620 {$ENDIF}
621 end;
623 function r_Render_WriteScreenShot (filename: String): Boolean;
624 begin
625 Result := False;
626 end;
628 {$IFDEF ENABLE_GIBS}
629 function r_Render_GetGibRect (m, id: Integer): TRectWH;
630 begin
631 result := r_Map_GetGibSize(m, id);
632 end;
633 {$ENDIF}
635 {$IFDEF ENABLE_GFX}
636 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
637 begin
638 r_Map_NewGFX(AnimType, X, Y);
639 end;
640 {$ENDIF}
642 {$IFDEF ENABLE_TOUCH}
643 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
644 begin
645 founded := False;
646 end;
647 {$ENDIF}
649 {$IFDEF ENABLE_MENU}
650 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
651 begin
652 r_GUI_GetSize(ctrl, w, h);
653 end;
655 procedure r_Render_GetLogoSize (out w, h: Integer);
656 begin
657 r_GUI_GetLogoSize(w, h);
658 end;
660 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
661 begin
662 r_GUI_GetMaxFontSize(BigFont, w, h);
663 end;
665 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
666 begin
667 r_GUI_GetStringSize(BigFont, str, w, h);
668 end;
669 {$ENDIF}
671 procedure r_Render_DrawLoading (force: Boolean);
672 begin
673 // TODO draw loading screen
674 end;
676 end.