DEADSOFTWARE

gl: implement font loading and drawing
[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_SYSTEM}
78 g_system,
79 {$ENDIF}
80 SysUtils, Classes, Math,
81 e_log, utils,
82 g_game, g_options, g_console,
83 r_draw, r_textures, r_fonts, r_map
84 ;
86 var
87 menuBG: TGLTexture;
88 stdfont: TGLFont;
89 smallfont: TGLFont;
90 menufont: TGLFont;
92 procedure r_Render_LoadTextures;
93 begin
94 r_Map_LoadTextures;
95 end;
97 procedure r_Render_FreeTextures;
98 begin
99 r_Map_FreeTextures;
100 end;
102 function r_Render_LoadFont (const name: AnsiString): TGLFont;
103 var info: TFontInfo; skiphack: Integer;
104 begin
105 result := nil;
106 if name = 'STD' then skiphack := 144 else skiphack := 0;
107 if r_Font_LoadInfoFromFile(GameWad + ':FONTS/' + name + 'TXT', info) then
108 result := r_Textures_LoadFontFromFile(GameWad + ':FONTS/' + name + 'FONT', info, skiphack, true);
109 if result = nil then
110 e_logwritefln('failed to load font %s', [name]);
111 end;
113 procedure r_Render_Load;
114 begin
115 menuBG := r_Textures_LoadFromFile(GameWAD + ':' + 'TEXTURES/TITLE');
116 stdfont := r_Render_LoadFont('STD');
117 smallfont := r_Render_LoadFont('SMALL');
118 menufont := r_Render_LoadFont('MENU');
119 r_Map_Load;
120 end;
122 procedure r_Render_Free;
123 begin
124 r_Map_Free;
125 menufont.Free;
126 smallfont.Free;
127 stdfont.Free;
128 menuBG.Free;
129 end;
131 {$IFDEF ENABLE_SYSTEM}
132 function GetInfo (): TGLDisplayInfo;
133 var info: TGLDisplayInfo;
134 begin
135 info := Default(TGLDisplayInfo);
136 info.w := Max(1, gRC_Width);
137 info.h := Max(1, gRC_Height);
138 info.bpp := Max(1, gBPP);
139 info.fullscreen := gRC_FullScreen;
140 info.maximized := gRC_Maximized;
141 info.major := 1;
142 info.minor := 1;
143 info.profile := TGLProfile.Compat;
144 result := info;
145 end;
146 {$ENDIF}
148 procedure r_Render_Initialize;
149 begin
150 {$IFDEF ENABLE_SYSTEM}
151 if sys_SetDisplayModeGL(GetInfo()) = False then
152 raise Exception.Create('Failed to set videomode on startup.');
153 sys_EnableVSync(gVSync);
154 {$ENDIF}
155 r_Textures_Initialize;
156 r_Map_Initialize;
157 end;
159 procedure r_Render_Finalize;
160 begin
161 r_Map_Finalize;
162 r_Textures_Finalize;
163 end;
165 procedure r_Render_Update;
166 begin
167 r_Map_Update;
168 end;
170 procedure SetupMatrix;
171 begin
172 glViewport(0, 0, gScreenWidth, gScreenHeight);
173 glScissor(0, 0, gScreenWidth, gScreenHeight);
174 glMatrixMode(GL_PROJECTION);
175 glLoadIdentity;
176 glOrtho(0, gScreenWidth, gScreenHeight, 0, 0, 1);
177 glMatrixMode(GL_MODELVIEW);
178 glLoadIdentity;
179 end;
181 procedure r_Render_Draw;
182 begin
183 if gExit = EXIT_QUIT then
184 exit;
186 SetupMatrix;
188 glClearColor(0.0, 0.0, 0.0, 0.0);
189 glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
191 glColor4ub(255, 255, 255, 255);
193 //e_LogWritefln('r_render_draw: %sx%s', [gScreenWidth, gScreenHeight]);
195 if gGameOn or (gState = STATE_FOLD) then
196 begin
197 // TODO setup player view
198 // TODO setup sectator mode
199 // TODO setup player hear point
200 // TODO setup player view siz
202 // TODO draw player view + setup screen coords
203 r_Map_Draw(0, 0, gScreenWidth, gScreenHeight, gPlayer1.obj.x + 32, gPlayer1.obj.y + 32, gPlayer1); // !!! remove unnamed consts
205 // TODO draw holmes inspector
207 // TODO draw messages
208 // TODO draw stats (?)
209 // TODO draw spectator hud
210 end;
212 if gPauseMain and gGameOn {$IFDEF ENABLE_MENU}and (g_ActiveWindow = nil){$ENDIF} then
213 begin
214 // TODO draw pause screen
215 end;
217 if not gGameOn then
218 begin
219 case gState of
220 STATE_MENU: ; // TODO draw menu bg
221 STATE_FOLD: ;
222 STATE_INTERCUSTOM: ;
223 STATE_INTERSINGLE: ;
224 STATE_ENDPIC: ;
225 STATE_SLIST: ;
226 end;
227 end;
229 {$IFDEF ENABLE_MENU}
230 if g_ActiveWindow <> nil then
231 begin
232 // TODO draw menu widgets
233 end;
234 {$ENDIF}
236 // TODO draw console
238 // TODO draw holmes interface
240 glFinish();
241 glFlush();
242 sys_Repaint;
243 end;
245 procedure r_Render_Resize (w, h: Integer);
246 begin
247 gWinSizeX := w;
248 gWinSizeY := h;
249 gRC_Width := w;
250 gRC_Height := h;
251 gScreenWidth := w;
252 gScreenHeight := h;
253 end;
255 procedure r_Render_Apply;
256 begin
257 {$IFDEF ENABLE_SYSTEM}
258 if sys_SetDisplayModeGL(GetInfo()) then
259 e_LogWriteln('resolution changed')
260 else
261 e_LogWriteln('resolution not changed');
262 sys_EnableVSync(gVSync)
263 {$ENDIF}
264 end;
266 function r_Render_WriteScreenShot (filename: String): Boolean;
267 begin
268 Result := False;
269 end;
271 {$IFDEF ENABLE_GIBS}
272 function r_Render_GetGibRect (m, id: Integer): TRectWH;
273 begin
274 result := r_Map_GetGibSize(m, id);
275 end;
276 {$ENDIF}
278 {$IFDEF ENABLE_GFX}
279 procedure r_Render_QueueEffect (AnimType, X, Y: Integer);
280 begin
281 r_Map_NewGFX(AnimType, X, Y);
282 end;
283 {$ENDIF}
285 {$IFDEF ENABLE_TOUCH}
286 procedure r_Render_GetKeyRect (key: Integer; out x, y, w, h: Integer; out founded: Boolean);
287 begin
288 founded := False;
289 end;
290 {$ENDIF}
292 {$IFDEF ENABLE_MENU}
293 procedure r_Render_GetControlSize (ctrl: TGUIControl; out w, h: Integer);
294 begin
295 w := 0; h := 0;
296 end;
298 procedure r_Render_GetLogoSize (out w, h: Integer);
299 begin
300 w := 0; h := 0;
301 end;
303 procedure r_Render_GetMaxFontSize (BigFont: Boolean; out w, h: Integer);
304 begin
305 w := 0; h := 0;
306 end;
308 procedure r_Render_GetStringSize (BigFont: Boolean; str: String; out w, h: Integer);
309 begin
310 w := 0; h := 0;
311 end;
312 {$ENDIF}
314 procedure r_Render_DrawLoading (force: Boolean);
315 begin
316 end;
318 end.