79506da918f8b42cc27522ac896b306acf6d592f
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 {$IFNDEF USE_SDL2}
19 {$FATAL SDL2 required for flexui sdlstandalone}
20 {$ENDIF}
22 interface
24 uses
25 SDL2,
26 sdlcarcass;
29 // ////////////////////////////////////////////////////////////////////////// //
30 // initialize OpenGL; set `gScreenWidth` and `gScreenHeight` before calling this
33 // call this to show built frame
35 // call this to push "quit" event into queue
37 // call this to process queued messages; result is `true` if quit event was received
40 // run main loop, call `buildFrameCB()` and `renderFrameCB()`, maintain the given FPS
44 implementation
46 uses
47 SysUtils;
50 var
56 // ////////////////////////////////////////////////////////////////////////// //
58 begin
63 // ////////////////////////////////////////////////////////////////////////// //
65 var
67 begin
71 if SDL_Init(sdlflags) < 0 then exit; //raise Exception.Create('SDL: Init failed: ' + SDL_GetError());
73 //SDL_Quit();
81 begin
88 begin
97 var
99 begin
105 // ////////////////////////////////////////////////////////////////////////// //
106 // true: quit
108 var
110 begin
114 begin
116 //if (ev.type_ = SDL_QUITEV) then exit;
122 // ////////////////////////////////////////////////////////////////////////// //
124 begin
131 var
134 begin
138 //if gFullscreen then wFlags := wFlags or SDL_WINDOW_FULLSCREEN;
139 //if gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED;
143 //if VSync then v := 1 else v := 0;
151 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); // lights; it is enough to have 1-bit stencil buffer for lighting
154 {
155 if gFullscreen then
156 begin
157 mode.w := gScreenWidth;
158 mode.h := gScreenHeight;
159 mode.format := 0;
160 mode.refresh_rate := 0;
161 mode.driverdata := nil;
162 if SDL_GetClosestDisplayMode(0, @mode, @cmode) = nil then
163 begin
164 gScreenWidth := 800;
165 gScreenHeight := 600;
166 end
167 else
168 begin
169 gScreenWidth := cmode.w;
170 gScreenHeight := cmode.h;
171 end;
172 end;
173 }
190 // run main loop, call `buildFrameCB()` and `renderFrameCB()`, maintain the given FPS
192 var
195 begin
203 begin
204 // calculate time to build and render next frame
208 begin
209 // time to build next frame
216 end
217 else
218 begin
219 // has to wait for some time
228 initialization
232 finalization