DEADSOFTWARE

gl: background aspect fix are special case
[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_map, 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;
108 hudrflag, hudrflags, hudrflagd: TGLTexture;
109 hudbflag, hudbflags, hudbflagd: TGLTexture;
111 procedure r_Render_LoadTextures;
112 begin
113 r_Map_LoadTextures;
114 end;
116 procedure r_Render_FreeTextures;
117 begin
118 r_Map_FreeTextures;
119 end;
121 procedure r_Render_Load;
122 const
123 WeapName: array [0..WP_LAST] of AnsiString = ('KASTET', 'SAW', 'PISTOL', 'SHOTGUN1', 'SHOTGUN2', 'MGUN', 'RLAUNCHER', 'PGUN', 'BFG', 'SPULEMET', 'FLAMETHROWER');
124 var
125 i: Integer;
126 begin
127 r_Common_Load;
128 BackgroundTexture := DEFAULT(THereTexture);
129 hud := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUD');
130 hudbg := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/HUDBG');
131 hudhp[false] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/MED2');
132 hudhp[true] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/BMED');
133 hudap := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/ARMORHUD');
134 for i := 0 to WP_LAST do
135 hudwp[i] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/' + WeapName[i]);
136 hudkey[0] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYR');
137 hudkey[1] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYG');
138 hudkey[2] := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/KEYB');
139 hudair := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/AIRBAR');
140 hudjet := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/JETBAR');
141 hudrflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_BASE');
142 hudrflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_STOLEN');
143 hudrflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_R_DROP');
144 hudbflag := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_BASE');
145 hudbflags := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_STOLEN');
146 hudbflagd := r_Textures_LoadFromFile(GameWAD + ':TEXTURES/FLAGHUD_B_DROP');
147 r_Console_Load;
148 r_Map_Load;
149 {$IFDEF ENABLE_MENU}
150 r_GUI_Load;
151 {$ENDIF}
152 end;
154 procedure r_Render_Free;
155 var i: Integer;
156 begin
157 {$IFDEF ENABLE_MENU}
158 r_GUI_Free;
159 {$ENDIF}
160 r_Map_Free;
161 r_Console_Free;
162 hudbflagd.Free;
163 hudbflags.Free;
164 hudbflag.Free;
165 hudrflagd.Free;
166 hudrflags.Free;
167 hudrflag.Free;
168 hudjet.Free;
169 hudair.Free;
170 hudkey[0].Free;
171 hudkey[1].Free;
172 hudkey[2].Free;
173 for i := 0 to WP_LAST do
174 begin
175 if hudwp[i] <> nil then
176 hudwp[i].Free;
177 hudwp[i] := nil;
178 end;
179 hudap.Free;
180 hudhp[true].Free;
181 hudhp[false].Free;
182 hudbg.Free;
183 hud.Free;
184 r_Common_FreeThis(BackgroundTexture);
185 r_Common_Free;
186 end;
188 {$IFDEF ENABLE_SYSTEM}
189 function GetInfo (): TGLDisplayInfo;
190 var info: TGLDisplayInfo;
191 begin
192 info := Default(TGLDisplayInfo);
193 info.w := Max(1, gRC_Width);
194 info.h := Max(1, gRC_Height);
195 info.bpp := Max(1, gBPP);
196 info.fullscreen := gRC_FullScreen;
197 info.maximized := gRC_Maximized;
198 info.major := 1;
199 info.minor := 1;
200 info.profile := TGLProfile.Compat;
201 result := info;
202 end;
203 {$ENDIF}
205 procedure r_Render_Initialize;
206 begin
207 {$IFDEF ENABLE_SYSTEM}
208 if sys_SetDisplayModeGL(GetInfo()) = False then
209 raise Exception.Create('Failed to set videomode on startup.');
210 sys_EnableVSync(gVSync);
211 {$ENDIF}
212 r_Textures_Initialize;
213 r_Console_Initialize;
214 r_Map_Initialize;
215 end;
217 procedure r_Render_Finalize;
218 begin
219 r_Map_Finalize;
220 r_Console_Finalize;
221 r_Textures_Finalize;
222 end;
224 procedure r_Render_Update;
225 begin
226 r_Console_Update;
227 r_Map_Update;
228 end;
230 procedure r_Render_GetBasePoint (x, y, w, h: Integer; p: TBasePoint; out xx, yy: Integer);
231 begin
232 case p of
233 TBasePoint.BP_LEFTUP, TBasePoint.BP_LEFT, TBasePoint.BP_LEFTDOWN: xx := x;
234 TBasePoint.BP_UP, TBasePoint.BP_CENTER, TBasePoint.BP_DOWN: xx := x - w div 2;
235 TBasePoint.BP_RIGHTUP, TBasePoint.BP_RIGHT, TBasePoint.BP_RIGHTDOWN: xx := x - w;
236 end;
237 case p of
238 TBasePoint.BP_LEFTUP, TBasePoint.BP_UP, TBasePoint.BP_RIGHTUP: yy := y;
239 TBasePoint.BP_LEFT, TBasePoint.BP_CENTER, TBasePoint.BP_RIGHT: yy := y - h div 2;
240 TBasePoint.BP_LEFTDOWN, TBasePoint.BP_DOWN, TBasePoint.BP_RIGHTDOWN: yy := y - h;
241 end;
242 end;
244 procedure r_Render_DrawText (const text: AnsiString; x, y: Integer; r, g, b, a: Byte; f: TGLFont; p: TBasePoint);
245 var w, h: Integer;
246 begin
247 if p <> TBasePoint.BP_LEFTUP then
248 begin
249 r_Draw_GetTextSize(text, f, w, h);
250 r_Render_GetBasePoint(x, y, w, h, p, x, y);
251 end;
252 r_Draw_Text(text, x, y, r, g, b, a, f);
253 end;
255 procedure r_Render_DrawTexture (img: TGLTexture; x, y, w, h: Integer; p: TBasePoint);
256 begin
257 r_Render_GetBasePoint(x, y, w, h, p, x, y);
258 r_Draw_TextureRepeat(img, x, y, w, h, false, 255, 255, 255, 255, false);
259 end;
261 procedure r_Render_DrawHUD (x, y: Integer; p: TPlayer);
262 var t: TGLTexture; s: AnsiString;
263 begin
264 ASSERT(p <> nil);
266 // hud area is 196 x 240 pixels
267 r_Render_DrawTexture(hud, x, y, hud.width, hud.height, TBasePoint.BP_LEFTUP);
268 r_Render_DrawText(p.name, x + 98, y + 16, 255, 0, 0, 255, smallfont, TBasePoint.BP_CENTER);
270 t := hudhp[R_BERSERK in p.FRulez];
271 r_Render_DrawTexture(t, x + 51, y + 61, t.width, t.height, TBasePoint.BP_CENTER);
272 r_Render_DrawTexture(hudap, x + 50, y + 85, hudap.width, hudap.height, TBasePoint.BP_CENTER);
274 r_Render_DrawText(IntToStr(MAX(0, p.health)), x + 174, y + 56, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
275 r_Render_DrawText(IntToStr(MAX(0, p.armor)), x + 174, y + 84, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
277 case p.CurrWeap of
278 WEAPON_KASTET, WEAPON_SAW: s := '--';
279 else s := IntToStr(p.GetAmmoByWeapon(p.CurrWeap));
280 end;
281 r_Render_DrawText(s, x + 174, y + 174, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHT);
283 if p.CurrWeap <= WP_LAST then
284 begin
285 t := hudwp[p.CurrWeap];
286 r_Render_DrawTexture(t, x + 18, y + 160, t.width, t.height, TBasePoint.BP_LEFTUP);
287 end;
289 if R_KEY_RED in p.FRulez then
290 r_Render_DrawTexture(hudkey[0], x + 76, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
291 if R_KEY_GREEN in p.FRulez then
292 r_Render_DrawTexture(hudkey[1], x + 93, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
293 if R_KEY_BLUE in p.FRulez then
294 r_Render_DrawTexture(hudkey[2], x + 110, y + 214, 16, 16, TBasePoint.BP_LEFTUP);
296 if p.JetFuel > 0 then
297 begin
298 r_Render_DrawTexture(hudair, x, y + 116, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
299 if p.air > 0 then
300 r_Draw_FillRect(x + 14, y + 116 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 116 + 4 + 4, 0, 0, 196, 255);
301 r_Render_DrawTexture(hudjet, x, y + 126, hudjet.width, hudjet.height, TBasePoint.BP_LEFTUP);
302 r_Draw_FillRect(x + 14, y + 126 + 4, x + 14 + 168 * p.JetFuel div JET_MAX, y + 126 + 4 + 4, 208, 0, 0, 255);
303 end
304 else
305 begin
306 r_Render_DrawTexture(hudair, x, y + 124, hudair.width, hudair.height, TBasePoint.BP_LEFTUP);
307 if p.air > 0 then
308 r_Draw_FillRect(x + 14, y + 124 + 4, x + 14 + 168 * p.air div AIR_MAX, y + 124 + 4 + 4, 0, 0, 196, 255);
309 end;
310 end;
312 procedure r_Render_DrawHUDArea (x, y, w, h: Integer; p: TPlayer);
313 var s: AnsiString;
314 begin
315 r_Render_DrawTexture(hudbg, x, y, w, h, TBasePoint.BP_LEFTUP);
317 if p <> nil then
318 r_Render_DrawHUD(x + w - 196 + 2, y, p);
320 if gShowPing and g_Game_IsClient then
321 begin
322 s := _lc[I_GAME_PING_HUD] + IntToStr(NetPeer.lastRoundTripTime) + _lc[I_NET_SLIST_PING_MS];
323 r_Render_DrawText(s, x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
324 end;
326 if p.Spectator then
327 begin
328 r_Render_DrawText(_lc[I_PLAYER_SPECT], x + 4, y + 242, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
329 r_Render_DrawText(_lc[I_PLAYER_SPECT2], x + 4, y + 258, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
330 r_Render_DrawText(_lc[I_PLAYER_SPECT1], x + 4, y + 274, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
331 if p.NoRespawn then
332 r_Render_DrawText(_lc[I_PLAYER_SPECT1S], x + 4, y + 290, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
333 end;
334 end;
336 procedure r_Render_DrawStatsView (x, y, w, h: Integer; p: TPlayer);
337 var fw, i, maxFrags, top, totalPlayers: Integer; sign: Char; stat: TPlayerStatArray; f: TGLTexture;
338 begin
339 ASSERT(p <> nil);
341 if gShowScore and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
342 begin
343 (* RED TEAM GOALS *)
344 fw := 0;
345 if gGameSettings.GameMode = GM_CTF then
346 begin
347 case gFlags[FLAG_RED].State of
348 FLAG_STATE_CAPTURED: f := hudrflags;
349 FLAG_STATE_DROPPED: f := hudrflagd;
350 otherwise f := hudrflag;
351 end;
352 if f <> nil then
353 begin
354 fw := f.width + 8; (* + space *)
355 r_Render_DrawTexture(f, x + w - 16, y + 240 - 72 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
356 end;
357 end;
358 r_Render_DrawText(IntToStr(gTeamStat[TEAM_RED].Score), x + w - 16 - fw, y + 240 - 72 - 4, TEAMCOLOR[TEAM_RED].R, TEAMCOLOR[TEAM_RED].G, TEAMCOLOR[TEAM_RED].B, 255, menufont, TBasePoint.BP_RIGHTUP);
360 (* BLUE TEAM GOALS *)
361 fw := 0;
362 if gGameSettings.GameMode = GM_CTF then
363 begin
364 case gFlags[FLAG_BLUE].State of
365 FLAG_STATE_CAPTURED: f := hudbflags;
366 FLAG_STATE_DROPPED: f := hudbflagd;
367 otherwise f := hudbflag;
368 end;
369 if f <> nil then
370 begin
371 fw := f.width + 8; (* + space *)
372 r_Render_DrawTexture(f, x + w - 16, y + 240 - 32 - 4, f.width, f.height, TBasePoint.BP_RIGHTUP);
373 end;
374 end;
375 r_Render_DrawText(IntToStr(gTeamStat[TEAM_BLUE].Score), x + w - 16 - fw, y + 240 - 32 - 4, TEAMCOLOR[TEAM_RED].R, TEAMCOLOR[TEAM_RED].G, TEAMCOLOR[TEAM_RED].B, 255, menufont, TBasePoint.BP_RIGHTUP);
376 end;
378 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
379 begin
380 if gShowStat then
381 begin
382 r_Render_DrawText(IntToStr(p.Frags), x + w - 16, y, 255, 0, 0, 255, menufont, TBasePoint.BP_RIGHTUP);
384 top := 1;
385 maxFrags := 0;
386 totalPlayers := 0;
387 stat := g_Player_GetStats();
388 if stat <> nil then
389 begin
390 totalPlayers := Length(stat);
391 for i := 0 to High(stat) do
392 begin
393 if stat[i].Name <> p.Name then
394 begin
395 maxFrags := MAX(maxFrags, stat[i].Frags);
396 if stat[i].Frags > p.Frags then
397 top := top + 1;
398 end;
399 end;
400 end;
401 if p.Frags >= maxFrags then sign := '+' else sign := '-';
402 r_Render_DrawText(IntToStr(top) + ' / ' + IntToStr(totalPlayers) + ' ' + sign + IntToStr(ABS(p.Frags - maxFrags)), x + w - 16, y + 32, 255, 0, 0, 255, smallfont, TBasePoint.BP_RIGHTUP);
403 end;
405 if gLMSRespawn > LMS_RESPAWN_NONE then
406 begin
407 r_Render_DrawText(_lc[I_GAME_WARMUP], x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
408 r_Render_DrawText(': ' + IntToStr((gLMSRespawnTime - gTime) div 1000), x + w - 16 - 64, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_LEFTDOWN);
409 end
410 else if gShowLives and (gGameSettings.MaxLives > 0) then
411 begin
412 r_Render_DrawText(IntToStr(p.Lives), x + w - 16, y + h, 0, 255, 0, 255, menufont, TBasePoint.BP_RIGHTDOWN);
413 end;
414 end;
415 end;
417 procedure r_Render_DrawView (x, y, w, h: Integer; p: TPlayer);
418 var l, t, r, b: Integer;
419 begin
420 r_Draw_GetRect(l, t, r, b);
421 r_Draw_SetRect(x, y, x + w, y + h);
423 if p <> nil then
424 begin
425 r_Map_Draw(x, y, w, h, p.obj.x + PLAYER_RECT_CX, p.obj.y + PLAYER_RECT_CY, p);
426 r_Render_DrawStatsView(x, y, w, h, p);
427 if p.Spectator and p.NoRespawn then
428 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);
429 end
430 else
431 begin
432 r_Map_Draw(x, y, w, h, 0, 0, nil);
433 end;
435 r_Draw_SetRect(l, t, r, b);
436 end;
438 procedure r_Render_DrawPlayerView (x, y, w, h: Integer; p: TPlayer);
439 var l, t, r, b: Integer;
440 begin
441 r_Draw_GetRect(l, t, r, b);
442 r_Draw_SetRect(x, y, x + w, y + h);
443 r_Render_DrawView(x, y, w - 196, h, p);
444 r_Render_DrawHUDArea(x + w - 196, y, 196, h, p);
445 r_Draw_SetRect(l, t, r, b);
446 end;
448 procedure r_Render_DrawBackgroundImage (img: TGLTexture);
449 var fw, w, h: LongInt;
450 begin
451 if img <> nil then
452 begin
453 img := BackgroundTexture.id;
454 if img.width = img.height then fw := img.width * 4 div 3 else fw := img.width; // fix aspect 4:3
455 r_Common_CalcAspect(fw, img.height, gScreenWidth, gScreenHeight, false, w, h);
456 r_Draw_Texture(img, gScreenWidth div 2 - w div 2, 0, w, h, false, 255, 255, 255, 255, false);
457 end
458 end;
460 procedure r_Render_DrawBackground (const name: AnsiString);
461 begin
462 if r_Common_LoadThis(name, BackgroundTexture) then
463 r_Render_DrawBackgroundImage(BackgroundTexture.id)
464 end;
466 procedure r_Render_DrawServerList (var SL: TNetServerList; var ST: TNetServerTable);
467 var ip: AnsiString; ww, hh, cw, ch, mw, mh, motdh, scrx, scry, i, mx, y: Integer; msg: SSArray; Srv: TNetServer;
468 begin
469 scrx := gScreenWidth div 2;
470 scry := gScreenHeight div 2;
472 r_Draw_GetTextSize(_lc[I_NET_SLIST], menufont, ww, hh);
473 r_Render_DrawText(_lc[I_NET_SLIST], gScreenWidth div 2, 16, 255, 255, 255, 255, menufont, TBasePoint.BP_UP);
475 r_Draw_GetTextSize('W', stdfont, cw, ch);
476 motdh := gScreenHeight - 49 - ch * b_Text_LineCount(slMOTD);
478 r_Draw_FillRect(16, 64, gScreenWidth - 16, motdh, 64, 64, 64, 145);
479 r_Draw_Rect(16, 64, gScreenWidth - 16, motdh, 255, 127, 0, 255);
481 r_Render_DrawText(_lc[I_NET_SLIST_HELP], gScreenWidth div 2, gScreenHeight - 8, 255, 255, 255, 255, stdfont, TBasePoint.BP_DOWN);
483 if slMOTD <> '' then
484 begin
485 r_Draw_FillRect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 64, 64, 64, 110);
486 r_Draw_Rect(16, motdh, gScreenWidth - 16, gScreenHeight - 44, 255, 127, 0, 255);
487 msg := Parse2(slMOTD, #10);
488 for i := 0 to High(msg) do
489 r_Render_DrawText(msg[i], 20, motdh + 3 + ch * i, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
490 end;
492 if not slReadUrgent and (slUrgent <> '') then
493 begin
494 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
495 r_Draw_FillRect(scrx - 256, scry - 60, scrx + 256, scry + 60, 64, 64, 64, 127);
496 r_Draw_Rect(scrx - 256, scry - 60, scrx + 256, scry + 60, 255, 127, 0, 255);
497 r_Draw_FillRect(scrx - 256, scry - 40, scrx + 256, scry - 40, 255, 127, 0, 255);
498 r_Render_DrawText(_lc[I_NET_SLIST_URGENT], scrx, scry - 58, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
499 msg := Parse2(slUrgent, #10);
500 for i := 0 to High(msg) do
501 r_Render_DrawText(msg[i], scrx - 253, scry - 38 + ch * i, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
502 r_Render_DrawText(_lc[I_NET_SLIST_URGENT_CONT], scrx, scry + 41, 255, 255, 255, 255, stdfont, TBasePoint.BP_UP);
503 r_Draw_FillRect(scrx - 256, scry + 40, scrx + 256, scry + 40, 255, 127, 0, 255);
504 end
505 else if SL = nil then
506 begin
507 r_Draw_FillRect(17, 65, gScreenWidth - 17, motdh - 1, 64, 64, 64, 127);
508 r_Draw_Rect(scrx - 192, scry - 10, scrx + 192, scry + 11, 255, 127, 0, 255);
509 r_Render_DrawText(slWaitStr, scrx, scry, 255, 255, 255, 255, stdfont, TBasePoint.BP_CENTER);
510 end
511 else
512 begin
513 y := 90;
514 if slSelection < Length(ST) then
515 begin
516 sy := y + 42 * slSelection - 4;
517 Srv := GetServerFromTable(slSelection, SL, ST);
518 ip := _lc[I_NET_ADDRESS] + ' ' + Srv.IP + ':' + IntToStr(Srv.Port);
519 ip := ip + ' ' + _lc[I_NET_SERVER_PASSWORD] + ' ';
520 if Srv.Password then ip := ip + _lc[I_MENU_YES] else ip := ip +_lc[I_MENU_NO];
521 end;
523 mw := gScreenWidth - 188;
524 mx := 16 + mw;
526 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy + 40, 64, 64, 64, 255);
527 r_Draw_FillRect(16 + 1, sy, gScreenWidth - 16 - 1, sy, 205, 205, 205, 255);
528 r_Draw_FillRect(16 + 1, sy + 41, gScreenWidth - 16 - 1, sy + 41, 255, 255, 255, 255);
530 r_Draw_FillRect(16, 85, gScreenWidth - 16, 85, 255, 127, 0, 255);
531 r_Draw_FillRect(16, motdh - 20, gScreenWidth - 16, motdh - 20, 255, 127, 0, 255);
533 r_Draw_FillRect(mx - 70, 64, mx - 70, motdh, 255, 127, 0, 255);
534 r_Draw_FillRect(mx, 64, mx, motdh - 20, 255, 127, 0, 255);
535 r_Draw_FillRect(mx + 52, 64, mx + 52, motdh - 20, 255, 127, 0, 255);
536 r_Draw_FillRect(mx + 104, 64, mx + 104, motdh - 20, 255, 127, 0, 255);
538 r_Render_DrawText('NAME/MAP', 18, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
539 r_Render_DrawText('PING', mx - 68, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
540 r_Render_DrawText('MODE', mx + 2, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
541 r_Render_DrawText('PLRS', mx + 54, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
542 r_Render_DrawText('VER', mx + 106, 68, 255, 127, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
544 for i := 0 to High(ST) do
545 begin
546 Srv := GetServerFromTable(i, SL, ST);
547 r_Render_DrawText(Srv.Name, 18, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
548 r_Render_DrawText(Srv.Map, 18, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
550 if Srv.Ping = 0 then
551 r_Render_DrawText('<1' + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
552 else if (Srv.Ping >= 0) and (Srv.Ping <= 999) then
553 r_Render_DrawText(IntToStr(Srv.Ping) + _lc[I_NET_SLIST_PING_MS], mx - 68, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP)
554 else
555 r_Render_DrawText(_lc[I_NET_SLIST_NO_ACCESS], mx - 68, y, 255, 0, 0, 255, stdfont, TBasePoint.BP_LEFTUP);
556 if Length(ST[I].Indices) > 1 then
557 r_Render_DrawText('<' + IntToStr(Length(ST[I].Indices)) + '>', mx - 68, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
559 r_Render_DrawText(g_Game_ModeToText(Srv.GameMode), mx + 2, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
561 r_Render_DrawText(IntToStr(Srv.Players) + '/' + IntToStr(Srv.MaxPlayers), mx + 54, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
562 r_Render_DrawText(IntToStr(Srv.LocalPl) + '+' + IntToStr(Srv.Bots), mx + 54, y + 16, 210, 210, 210, 255, stdfont, TBasePoint.BP_LEFTUP);
564 r_Render_DrawText(IntToStr(Srv.Protocol), mx + 106, y, 255, 255, 255, 255, stdfont, TBasePoint.BP_LEFTUP);
566 y := y + 42;
567 end;
569 r_Render_DrawText(ip, 20, motdh - 20 + 3, 205, 205, 205, 255, stdfont, TBasePoint.BP_LEFTUP);
570 r_Render_DrawText(IntToStr(Length(ST)) + _lc[I_NET_SLIST_SERVERS], gScreenWidth - 48, motdh - 20 + 3, 255, 255, 255, 255, stdfont, TBasePoint.BP_RIGHTUP);
571 end;
572 end;
574 procedure r_Render_Draw;
575 begin
576 if gExit = EXIT_QUIT then
577 exit;
579 r_Draw_Setup(gScreenWidth, gScreenHeight);
581 glClearColor(0.0, 0.0, 0.0, 0.0);
582 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
584 glColor4ub(255, 255, 255, 255);
585 glEnable(GL_SCISSOR_TEST);
586 r_Draw_SetRect(0, 0, gScreenWidth, gScreenHeight);
588 //e_LogWritefln('r_render_draw: %sx%s', [gScreenWidth, gScreenHeight]);
590 if gGameOn or ((gState in [STATE_FOLD]) and (EndingGameCounter < 255)) then
591 begin
592 // TODO setup sectator mode
593 // TODO setup player hear point
595 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
596 begin
597 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight div 2 - 2, gPlayer1);
598 r_Render_DrawPlayerView(0, gScreenHeight div 2 + 2, gScreenWidth, gScreenHeight div 2, gPlayer2);
599 end
600 else
601 begin
602 r_Render_DrawPlayerView(0, 0, gScreenWidth, gScreenHeight, gPlayer1);
603 end;
605 // TODO draw holmes inspector
607 // TODO draw messages
608 // TODO draw stats (?)
609 // TODO draw spectator hud
610 end;
612 if gPauseMain and gGameOn {$IFDEF ENABLE_MENU}and (g_ActiveWindow = nil){$ENDIF} then
613 begin
614 // TODO draw pause screen
615 end;
617 if not gGameOn then
618 begin
619 case gState of
620 STATE_NONE: (* do nothing *) ;
621 STATE_MENU: r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
622 STATE_FOLD:
623 begin
624 if EndingGameCounter > 0 then
625 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
626 end;
627 STATE_INTERCUSTOM:
628 begin
629 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
630 if EndPicPath <> '' then
631 r_Render_DrawBackground(EndPicPath)
632 else
633 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC])
634 else
635 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
636 // TODO draw custom stata
637 {$IFDEF ENABLE_MENU}
638 if g_ActiveWindow <> nil then
639 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
640 {$ENDIF}
641 end;
642 STATE_INTERSINGLE, STATE_INTERTEXT, STATE_INTERPIC:
643 begin
644 if EndingGameCounter > 0 then
645 begin
646 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, MIN(MAX(255 - EndingGameCounter, 0), 255));
647 end
648 else
649 begin
650 r_Render_DrawBackground(GameWad + ':TEXTURES/INTER');
651 // TODO darw single stats
652 {$IFDEF ENABLE_MENU}
653 if g_ActiveWindow <> nil then
654 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
655 {$ENDIF}
656 end;
657 end;
658 STATE_ENDPIC:
659 begin
660 if EndPicPath <> '' then
661 r_Render_DrawBackground(EndPicPath)
662 else
663 r_Render_DrawBackground(GameWad + ':TEXTURES/' + _lc[I_TEXTURE_ENDPIC]);
664 {$IFDEF ENABLE_MENU}
665 if g_ActiveWindow <> nil then
666 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
667 {$ENDIF}
668 end;
669 STATE_SLIST:
670 begin
671 r_Render_DrawBackground(GameWad + ':TEXTURES/TITLE');
672 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
673 r_Render_DrawServerList(slCurrent, slTable);
674 end;
675 end;
676 end;
678 {$IFDEF ENABLE_MENU}
679 if g_ActiveWindow <> nil then
680 begin
681 if gGameOn then
682 r_Draw_FillRect(0, 0, gScreenWidth - 1, gScreenHeight - 1, 0, 0, 0, 105);
683 r_GUI_Draw_Window(g_ActiveWindow);
684 end;
685 {$ENDIF}
687 r_Console_Draw(false);
689 // TODO draw holmes interface
691 glFlush();
692 glFinish();
693 sys_Repaint;
694 end;
696 procedure r_Render_Resize (w, h: Integer);
697 begin
698 gWinSizeX := w;
699 gWinSizeY := h;
700 gRC_Width := w;
701 gRC_Height := h;
702 gScreenWidth := w;
703 gScreenHeight := h;
704 end;
706 procedure r_Render_Apply;
707 begin
708 {$IFDEF ENABLE_SYSTEM}
709 if sys_SetDisplayModeGL(GetInfo()) then
710 e_LogWriteln('resolution changed')
711 else
712 e_LogWriteln('resolution not changed');
713 sys_EnableVSync(gVSync)
714 {$ENDIF}
715 end;
717 function r_Render_WriteScreenShot (filename: String): Boolean;
718 begin
719 Result := False;
720 end;
722 {$IFDEF ENABLE_GIBS}
723 function r_Render_GetGibRect (m, id: Integer): TRectWH;
724 begin
725 result := r_Map_GetGibSize(m, id);
726 end;
727 {$ENDIF}
729 {$IFDEF ENABLE_GFX}
730 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
731 begin
732 r_Map_NewGFX(AnimType, X, Y);
733 end;
734 {$ENDIF}
736 {$IFDEF ENABLE_TOUCH}
737 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
738 begin
739 founded := False;
740 end;
741 {$ENDIF}
743 {$IFDEF ENABLE_MENU}
744 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
745 begin
746 r_GUI_GetSize(ctrl, w, h);
747 end;
749 procedure r_Render_GetLogoSize (out w, h: Integer);
750 begin
751 r_GUI_GetLogoSize(w, h);
752 end;
754 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
755 begin
756 r_GUI_GetMaxFontSize(BigFont, w, h);
757 end;
759 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
760 begin
761 r_GUI_GetStringSize(BigFont, str, w, h);
762 end;
763 {$ENDIF}
765 procedure r_Render_DrawLoading (force: Boolean);
766 begin
767 // TODO draw loading screen
768 end;
770 end.