1 (* Copyright (C) Doom 2D: Forever Developers
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.
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.
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/>.
15 {$INCLUDE ../../../shared/a_modes.inc}
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;
48 function r_Render_GetGibRect (m
, id
: Integer): TRectWH
;
52 procedure r_Render_QueueEffect (AnimType
, X
, Y
: Integer);
56 // touch screen button location and size
57 procedure r_Render_GetKeyRect (key
: Integer; out x
, y
, w
, h
: Integer; out founded
: Boolean);
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);
67 procedure r_Render_DrawLoading (force
: Boolean); // !!! remove it
80 {$IFDEF ENABLE_SYSTEM}
83 SysUtils
, Classes
, Math
,
85 g_game
, g_options
, g_console
, g_player
, g_weapons
, g_language
,
87 r_draw
, r_textures
, r_fonts
, r_common
, r_console
, r_map
92 BP_LEFTUP
, BP_UP
, BP_RIGHTUP
,
93 BP_LEFT
, BP_CENTER
, BP_RIGHT
,
94 BP_LEFTDOWN
, BP_DOWN
, BP_RIGHTDOWN
100 hud
, hudbg
: TGLTexture
;
101 hudhp
: array [Boolean] of TGLTexture
;
103 hudwp
: array [0..WP_LAST
] of TGLTexture
;
104 hudkey
: array [0..2] of TGLTexture
;
108 procedure r_Render_LoadTextures
;
113 procedure r_Render_FreeTextures
;
118 procedure r_Render_Load
;
120 WeapName
: array [0..WP_LAST
] of AnsiString = ('KASTET', 'SAW', 'PISTOL', 'SHOTGUN1', 'SHOTGUN2', 'MGUN', 'RLAUNCHER', 'PGUN', 'BFG', 'SPULEMET', 'FLAMETHROWER');
125 menuBG
:= r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/TITLE');
126 hud
:= r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/HUD');
127 hudbg
:= r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/HUDBG');
128 hudhp
[false] := r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/MED2');
129 hudhp
[true] := r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/BMED');
130 hudap
:= r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/ARMORHUD');
131 for i
:= 0 to WP_LAST
do
132 hudwp
[i
] := r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/' + WeapName
[i
]);
133 hudkey
[0] := r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/KEYR');
134 hudkey
[1] := r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/KEYG');
135 hudkey
[2] := r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/KEYB');
136 hudair
:= r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/AIRBAR');
137 hudjet
:= r_Textures_LoadFromFile(GameWAD
+ ':TEXTURES/JETBAR');
145 procedure r_Render_Free
;
158 for i
:= 0 to WP_LAST
do
160 if hudwp
[i
] <> nil then
173 {$IFDEF ENABLE_SYSTEM}
174 function GetInfo (): TGLDisplayInfo
;
175 var info
: TGLDisplayInfo
;
177 info
:= Default(TGLDisplayInfo
);
178 info
.w
:= Max(1, gRC_Width
);
179 info
.h
:= Max(1, gRC_Height
);
180 info
.bpp
:= Max(1, gBPP
);
181 info
.fullscreen
:= gRC_FullScreen
;
182 info
.maximized
:= gRC_Maximized
;
185 info
.profile
:= TGLProfile
.Compat
;
190 procedure r_Render_Initialize
;
192 {$IFDEF ENABLE_SYSTEM}
193 if sys_SetDisplayModeGL(GetInfo()) = False then
194 raise Exception
.Create('Failed to set videomode on startup.');
195 sys_EnableVSync(gVSync
);
197 r_Textures_Initialize
;
198 r_Console_Initialize
;
202 procedure r_Render_Finalize
;
209 procedure r_Render_Update
;
215 procedure SetupMatrix
;
217 glViewport(0, 0, gScreenWidth
, gScreenHeight
);
218 glScissor(0, 0, gScreenWidth
, gScreenHeight
);
219 glMatrixMode(GL_PROJECTION
);
221 glOrtho(0, gScreenWidth
, gScreenHeight
, 0, 0, 1);
222 glMatrixMode(GL_MODELVIEW
);
226 procedure r_Render_GetBasePoint (x
, y
, w
, h
: Integer; p
: TBasePoint
; out xx
, yy
: Integer);
229 TBasePoint
.BP_LEFTUP
, TBasePoint
.BP_LEFT
, TBasePoint
.BP_LEFTDOWN
: xx
:= x
;
230 TBasePoint
.BP_UP
, TBasePoint
.BP_CENTER
, TBasePoint
.BP_DOWN
: xx
:= x
- w
div 2;
231 TBasePoint
.BP_RIGHTUP
, TBasePoint
.BP_RIGHT
, TBasePoint
.BP_RIGHTDOWN
: xx
:= x
- w
;
234 TBasePoint
.BP_LEFTUP
, TBasePoint
.BP_UP
, TBasePoint
.BP_RIGHTUP
: yy
:= y
;
235 TBasePoint
.BP_LEFT
, TBasePoint
.BP_CENTER
, TBasePoint
.BP_RIGHT
: yy
:= y
- h
div 2;
236 TBasePoint
.BP_LEFTDOWN
, TBasePoint
.BP_DOWN
, TBasePoint
.BP_RIGHTDOWN
: yy
:= y
- h
;
240 procedure r_Render_DrawText (const text: AnsiString; x
, y
: Integer; r
, g
, b
, a
: Byte; f
: TGLFont
; p
: TBasePoint
);
243 if p
<> TBasePoint
.BP_LEFTUP
then
245 r_Draw_GetTextSize(text, f
, w
, h
);
246 r_Render_GetBasePoint(x
, y
, w
, h
, p
, x
, y
);
248 r_Draw_Text(text, x
, y
, r
, g
, b
, a
, f
);
251 procedure r_Render_DrawTexture (img
: TGLTexture
; x
, y
, w
, h
: Integer; p
: TBasePoint
);
253 r_Render_GetBasePoint(x
, y
, w
, h
, p
, x
, y
);
254 r_Draw_TextureRepeat(img
, x
, y
, w
, h
, false, 255, 255, 255, 255, false);
257 procedure r_Render_DrawHUD (x
, y
: Integer; p
: TPlayer
);
258 var t
: TGLTexture
; s
: AnsiString;
262 // hud area is 196 x 240 pixels
263 r_Render_DrawTexture(hud
, x
, y
, hud
.width
, hud
.height
, TBasePoint
.BP_LEFTUP
);
264 r_Render_DrawText(p
.name
, x
+ 98, y
+ 16, 255, 0, 0, 255, smallfont
, TBasePoint
.BP_CENTER
);
266 t
:= hudhp
[R_BERSERK
in p
.FRulez
];
267 r_Render_DrawTexture(t
, x
+ 51, y
+ 61, t
.width
, t
.height
, TBasePoint
.BP_CENTER
);
268 r_Render_DrawTexture(hudap
, x
+ 50, y
+ 85, hudap
.width
, hudap
.height
, TBasePoint
.BP_CENTER
);
270 r_Render_DrawText(IntToStr(MAX(0, p
.health
)), x
+ 174, y
+ 56, 255, 0, 0, 255, menufont
, TBasePoint
.BP_RIGHT
);
271 r_Render_DrawText(IntToStr(MAX(0, p
.armor
)), x
+ 174, y
+ 84, 255, 0, 0, 255, menufont
, TBasePoint
.BP_RIGHT
);
274 WEAPON_KASTET
, WEAPON_SAW
: s
:= '--';
275 else s
:= IntToStr(p
.GetAmmoByWeapon(p
.CurrWeap
));
277 r_Render_DrawText(s
, x
+ 174, y
+ 174, 255, 0, 0, 255, menufont
, TBasePoint
.BP_RIGHT
);
279 if p
.CurrWeap
<= WP_LAST
then
281 t
:= hudwp
[p
.CurrWeap
];
282 r_Render_DrawTexture(t
, x
+ 18, y
+ 160, t
.width
, t
.height
, TBasePoint
.BP_LEFTUP
);
285 if R_KEY_RED
in p
.FRulez
then
286 r_Render_DrawTexture(hudkey
[0], x
+ 76, y
+ 214, 16, 16, TBasePoint
.BP_LEFTUP
);
287 if R_KEY_GREEN
in p
.FRulez
then
288 r_Render_DrawTexture(hudkey
[1], x
+ 93, y
+ 214, 16, 16, TBasePoint
.BP_LEFTUP
);
289 if R_KEY_BLUE
in p
.FRulez
then
290 r_Render_DrawTexture(hudkey
[2], x
+ 110, y
+ 214, 16, 16, TBasePoint
.BP_LEFTUP
);
292 if p
.JetFuel
> 0 then
294 r_Render_DrawTexture(hudair
, x
, y
+ 116, hudair
.width
, hudair
.height
, TBasePoint
.BP_LEFTUP
);
296 r_Draw_FillRect(x
+ 14, y
+ 116 + 4, x
+ 14 + 168 * p
.air
div AIR_MAX
, y
+ 116 + 4 + 4, 0, 0, 196, 255);
297 r_Render_DrawTexture(hudjet
, x
, y
+ 126, hudjet
.width
, hudjet
.height
, TBasePoint
.BP_LEFTUP
);
298 r_Draw_FillRect(x
+ 14, y
+ 126 + 4, x
+ 14 + 168 * p
.JetFuel
div JET_MAX
, y
+ 126 + 4 + 4, 208, 0, 0, 255);
302 r_Render_DrawTexture(hudair
, x
, y
+ 124, hudair
.width
, hudair
.height
, TBasePoint
.BP_LEFTUP
);
304 r_Draw_FillRect(x
+ 14, y
+ 124 + 4, x
+ 14 + 168 * p
.air
div AIR_MAX
, y
+ 124 + 4 + 4, 0, 0, 196, 255);
308 procedure r_Render_DrawHUDArea (x
, y
, w
, h
: Integer; p
: TPlayer
);
311 r_Render_DrawTexture(hudbg
, x
, y
, w
, h
, TBasePoint
.BP_LEFTUP
);
314 r_Render_DrawHUD(x
+ w
- 196 + 2, y
, p
);
316 if gShowPing
and g_Game_IsClient
then
318 s
:= _lc
[I_GAME_PING_HUD
] + IntToStr(NetPeer
.lastRoundTripTime
) + _lc
[I_NET_SLIST_PING_MS
];
319 r_Render_DrawText(s
, x
+ 4, y
+ 242, 255, 255, 255, 255, stdfont
, TBasePoint
.BP_LEFTUP
);
324 r_Render_DrawText(_lc
[I_PLAYER_SPECT
], x
+ 4, y
+ 242, 255, 255, 255, 255, stdfont
, TBasePoint
.BP_LEFTUP
);
325 r_Render_DrawText(_lc
[I_PLAYER_SPECT2
], x
+ 4, y
+ 258, 255, 255, 255, 255, stdfont
, TBasePoint
.BP_LEFTUP
);
326 r_Render_DrawText(_lc
[I_PLAYER_SPECT1
], x
+ 4, y
+ 274, 255, 255, 255, 255, stdfont
, TBasePoint
.BP_LEFTUP
);
328 r_Render_DrawText(_lc
[I_PLAYER_SPECT1S
], x
+ 4, y
+ 290, 255, 255, 255, 255, stdfont
, TBasePoint
.BP_LEFTUP
);
332 procedure r_Render_DrawView (x
, y
, w
, h
: Integer; p
: TPlayer
);
335 r_Map_Draw(x
, y
, w
, h
, p
.obj
.x
+ PLAYER_RECT_CX
, p
.obj
.y
+ PLAYER_RECT_CY
, p
)
337 r_Map_Draw(x
, y
, w
, h
, 0, 0, nil);
343 if p
.Spectator
and p
.NoRespawn
then
344 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
);
348 procedure r_Render_DrawPlayerView (x
, y
, w
, h
: Integer; p
: TPlayer
);
350 r_Render_DrawView(x
, y
, w
- 196, h
, p
);
351 r_Render_DrawHUDArea(x
+ w
- 196, y
, 196, h
, p
);
354 procedure r_Render_Draw
;
356 if gExit
= EXIT_QUIT
then
361 glClearColor(0.0, 0.0, 0.0, 0.0);
362 glClear(GL_COLOR_BUFFER_BIT
or GL_DEPTH_BUFFER_BIT
);
364 glColor4ub(255, 255, 255, 255);
366 //e_LogWritefln('r_render_draw: %sx%s', [gScreenWidth, gScreenHeight]);
368 if gGameOn
or (gState
= STATE_FOLD
) then
370 // TODO setup player view
371 // TODO setup sectator mode
372 // TODO setup player hear point
373 // TODO setup player view siz
375 // TODO draw player view + setup screen coords
376 r_Render_DrawPlayerView(0, 0, gScreenWidth
, gScreenHeight
, gPlayer1
);
378 // TODO draw holmes inspector
380 // TODO draw messages
381 // TODO draw stats (?)
382 // TODO draw spectator hud
385 if gPauseMain
and gGameOn
{$IFDEF ENABLE_MENU}and (g_ActiveWindow
= nil){$ENDIF} then
387 // TODO draw pause screen
393 STATE_MENU
: ; // TODO draw menu bg
403 if g_ActiveWindow
<> nil then
406 r_Draw_FillRect(0, 0, gScreenWidth
- 1, gScreenHeight
- 1, 0, 0, 0, 105);
407 r_GUI_Draw_Window(g_ActiveWindow
);
411 r_Console_Draw(false);
413 // TODO draw holmes interface
420 procedure r_Render_Resize (w
, h
: Integer);
430 procedure r_Render_Apply
;
432 {$IFDEF ENABLE_SYSTEM}
433 if sys_SetDisplayModeGL(GetInfo()) then
434 e_LogWriteln('resolution changed')
436 e_LogWriteln('resolution not changed');
437 sys_EnableVSync(gVSync
)
441 function r_Render_WriteScreenShot (filename
: String): Boolean;
447 function r_Render_GetGibRect (m
, id
: Integer): TRectWH
;
449 result
:= r_Map_GetGibSize(m
, id
);
454 procedure r_Render_QueueEffect (AnimType
, X
, Y
: Integer);
456 r_Map_NewGFX(AnimType
, X
, Y
);
460 {$IFDEF ENABLE_TOUCH}
461 procedure r_Render_GetKeyRect (key
: Integer; out x
, y
, w
, h
: Integer; out founded
: Boolean);
468 procedure r_Render_GetControlSize (ctrl
: TGUIControl
; out w
, h
: Integer);
470 r_GUI_GetSize(ctrl
, w
, h
);
473 procedure r_Render_GetLogoSize (out w
, h
: Integer);
475 r_GUI_GetLogoSize(w
, h
);
478 procedure r_Render_GetMaxFontSize (BigFont
: Boolean; out w
, h
: Integer);
480 r_GUI_GetMaxFontSize(BigFont
, w
, h
);
483 procedure r_Render_GetStringSize (BigFont
: Boolean; str
: String; out w
, h
: Integer);
485 r_GUI_GetStringSize(BigFont
, str
, w
, h
);
489 procedure r_Render_DrawLoading (force
: Boolean);
491 // TODO draw loading screen