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, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
19 interface
21 uses
22 SDL2,
23 sdlcarcass;
26 // ////////////////////////////////////////////////////////////////////////// //
27 // initialize OpenGL; set `gScreenWidth` and `gScreenHeight` before calling this
30 // call this to show built frame
32 // call this to push "quit" event into queue
34 // call this to process queued messages; result is `true` if quit event was received
37 // run main loop, call `buildFrameCB()` and `renderFrameCB()`, maintain the given FPS
41 implementation
43 uses
44 SysUtils;
47 var
53 // ////////////////////////////////////////////////////////////////////////// //
55 begin
60 // ////////////////////////////////////////////////////////////////////////// //
62 var
64 begin
68 if SDL_Init(sdlflags) < 0 then exit; //raise Exception.Create('SDL: Init failed: ' + SDL_GetError());
70 //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;
117 // ////////////////////////////////////////////////////////////////////////// //
119 begin
126 var
129 begin
133 //if gFullscreen then wFlags := wFlags or SDL_WINDOW_FULLSCREEN;
134 //if gWinMaximized then wFlags := wFlags or SDL_WINDOW_MAXIMIZED;
138 //if VSync then v := 1 else v := 0;
146 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); // lights; it is enough to have 1-bit stencil buffer for lighting
149 {
150 if gFullscreen then
151 begin
152 mode.w := gScreenWidth;
153 mode.h := gScreenHeight;
154 mode.format := 0;
155 mode.refresh_rate := 0;
156 mode.driverdata := nil;
157 if SDL_GetClosestDisplayMode(0, @mode, @cmode) = nil then
158 begin
159 gScreenWidth := 800;
160 gScreenHeight := 600;
161 end
162 else
163 begin
164 gScreenWidth := cmode.w;
165 gScreenHeight := cmode.h;
166 end;
167 end;
168 }
185 // run main loop, call `buildFrameCB()` and `renderFrameCB()`, maintain the given FPS
187 var
190 begin
198 begin
199 // calculate time to build and render next frame
203 begin
204 // time to build next frame
211 end
212 else
213 begin
214 // has to wait for some time
223 initialization
227 finalization