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}
18 interface
20 uses
21 SDL2,
22 sdlcarcass;
25 // ////////////////////////////////////////////////////////////////////////// //
26 // initialize OpenGL; set `gScreenWidth` and `gScreenHeight` before calling this
29 // call this to show built frame
31 // call this to push "quit" event into queue
33 // call this to process queued messages; result is `true` if quit event was received
36 // run main loop, call `buildFrameCB()` and `renderFrameCB()`, maintain the given FPS
40 implementation
42 uses
43 SysUtils;
46 var
52 // ////////////////////////////////////////////////////////////////////////// //
54 begin
59 // ////////////////////////////////////////////////////////////////////////// //
61 var
63 begin
67 if SDL_Init(sdlflags) < 0 then exit; //raise Exception.Create('SDL: Init failed: ' + SDL_GetError());
69 //SDL_Quit();
77 begin
84 begin
93 var
95 begin
101 // ////////////////////////////////////////////////////////////////////////// //
102 // true: quit
104 var
106 begin
110 begin
112 //if (ev.type_ = SDL_QUITEV) then exit;
118 // ////////////////////////////////////////////////////////////////////////// //
120 begin
127 var
130 begin
134 //if gFullscreen then wFlags := wFlags or SDL_WINDOW_FULLSCREEN;
135 //if gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED;
139 //if VSync then v := 1 else v := 0;
147 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); // lights; it is enough to have 1-bit stencil buffer for lighting
150 {
151 if gFullscreen then
152 begin
153 mode.w := gScreenWidth;
154 mode.h := gScreenHeight;
155 mode.format := 0;
156 mode.refresh_rate := 0;
157 mode.driverdata := nil;
158 if SDL_GetClosestDisplayMode(0, @mode, @cmode) = nil then
159 begin
160 gScreenWidth := 800;
161 gScreenHeight := 600;
162 end
163 else
164 begin
165 gScreenWidth := cmode.w;
166 gScreenHeight := cmode.h;
167 end;
168 end;
169 }
186 // run main loop, call `buildFrameCB()` and `renderFrameCB()`, maintain the given FPS
188 var
191 begin
199 begin
200 // calculate time to build and render next frame
204 begin
205 // time to build next frame
212 end
213 else
214 begin
215 // has to wait for some time
224 initialization
228 finalization