Bevel mod: cleanup flags and extra data.
[blender.git] / extern / sdlew / src / sdlew.c
1 /*
2  * Copyright 2014 Blender Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License
15  */
16
17 #ifdef _MSC_VER
18 #  define snprintf _snprintf
19 #  define popen _popen
20 #  define pclose _pclose
21 #  define _CRT_SECURE_NO_WARNINGS
22 #endif
23
24 #include "sdlew.h"
25
26 #include "SDL2/SDL.h"
27 #include "SDL2/SDL_syswm.h"
28
29 #include <assert.h>
30 #include <stdio.h>
31 #include <string.h>
32 #include <sys/stat.h>
33
34 #ifdef _WIN32
35 #  define WIN32_LEAN_AND_MEAN
36 #  define VC_EXTRALEAN
37 #  include <windows.h>
38
39 /* Utility macros. */
40
41 typedef HMODULE DynamicLibrary;
42
43 #  define dynamic_library_open(path)         LoadLibrary(path)
44 #  define dynamic_library_close(lib)         FreeLibrary(lib)
45 #  define dynamic_library_find(lib, symbol)  GetProcAddress(lib, symbol)
46 #else
47 #  include <dlfcn.h>
48
49 typedef void* DynamicLibrary;
50
51 #  define dynamic_library_open(path)         dlopen(path, RTLD_NOW)
52 #  define dynamic_library_close(lib)         dlclose(lib)
53 #  define dynamic_library_find(lib, symbol)  dlsym(lib, symbol)
54 #endif
55
56 #define SDL_LIBRARY_FIND_CHECKED(name)         name = (t##name *)dynamic_library_find(lib, #name);         assert(name);
57
58 #define SDL_LIBRARY_FIND(name)         name = (t##name *)dynamic_library_find(lib, #name);
59
60 static DynamicLibrary lib;
61
62 tSDL_GetPlatform *SDL_GetPlatform;
63 tSDL_memcpy *SDL_memcpy;
64 #ifndef HAVE_ALLOCA
65 tSDL_malloc *SDL_malloc;
66 #endif
67 tSDL_calloc *SDL_calloc;
68 tSDL_realloc *SDL_realloc;
69 tSDL_free *SDL_free;
70 tSDL_getenv *SDL_getenv;
71 tSDL_setenv *SDL_setenv;
72 tSDL_qsort *SDL_qsort;
73 tSDL_abs *SDL_abs;
74 tSDL_isdigit *SDL_isdigit;
75 tSDL_isspace *SDL_isspace;
76 tSDL_toupper *SDL_toupper;
77 tSDL_tolower *SDL_tolower;
78 tSDL_memset *SDL_memset;
79 tSDL_memmove *SDL_memmove;
80 tSDL_memcmp *SDL_memcmp;
81 tSDL_wcslen *SDL_wcslen;
82 tSDL_wcslcpy *SDL_wcslcpy;
83 tSDL_wcslcat *SDL_wcslcat;
84 tSDL_strlen *SDL_strlen;
85 tSDL_strlcpy *SDL_strlcpy;
86 tSDL_utf8strlcpy *SDL_utf8strlcpy;
87 tSDL_strlcat *SDL_strlcat;
88 tSDL_strdup *SDL_strdup;
89 tSDL_strrev *SDL_strrev;
90 tSDL_strupr *SDL_strupr;
91 tSDL_strlwr *SDL_strlwr;
92 tSDL_strchr *SDL_strchr;
93 tSDL_strrchr *SDL_strrchr;
94 tSDL_strstr *SDL_strstr;
95 tSDL_itoa *SDL_itoa;
96 tSDL_uitoa *SDL_uitoa;
97 tSDL_ltoa *SDL_ltoa;
98 tSDL_ultoa *SDL_ultoa;
99 tSDL_lltoa *SDL_lltoa;
100 tSDL_ulltoa *SDL_ulltoa;
101 tSDL_atoi *SDL_atoi;
102 tSDL_atof *SDL_atof;
103 tSDL_strtol *SDL_strtol;
104 tSDL_strtoll *SDL_strtoll;
105 tSDL_strtoull *SDL_strtoull;
106 tSDL_strtod *SDL_strtod;
107 tSDL_strcmp *SDL_strcmp;
108 tSDL_strncmp *SDL_strncmp;
109 tSDL_strcasecmp *SDL_strcasecmp;
110 tSDL_strncasecmp *SDL_strncasecmp;
111 tSDL_sscanf *SDL_sscanf;
112 tSDL_snprintf *SDL_snprintf;
113 tSDL_vsnprintf *SDL_vsnprintf;
114 tSDL_atan *SDL_atan;
115 tSDL_atan2 *SDL_atan2;
116 tSDL_ceil *SDL_ceil;
117 tSDL_copysign *SDL_copysign;
118 tSDL_cos *SDL_cos;
119 tSDL_cosf *SDL_cosf;
120 tSDL_fabs *SDL_fabs;
121 tSDL_floor *SDL_floor;
122 tSDL_log *SDL_log;
123 tSDL_pow *SDL_pow;
124 tSDL_scalbn *SDL_scalbn;
125 tSDL_sin *SDL_sin;
126 tSDL_sinf *SDL_sinf;
127 tSDL_sqrt *SDL_sqrt;
128 tSDL_iconv_open *SDL_iconv_open;
129 tSDL_iconv_close *SDL_iconv_close;
130 tSDL_iconv *SDL_iconv;
131 tSDL_iconv_string *SDL_iconv_string;
132 tSDL_GetNumRenderDrivers *SDL_GetNumRenderDrivers;
133 tSDL_GetRenderDriverInfo *SDL_GetRenderDriverInfo;
134 tSDL_CreateWindowAndRenderer *SDL_CreateWindowAndRenderer;
135 tSDL_CreateRenderer *SDL_CreateRenderer;
136 tSDL_CreateSoftwareRenderer *SDL_CreateSoftwareRenderer;
137 tSDL_GetRenderer *SDL_GetRenderer;
138 tSDL_GetRendererInfo *SDL_GetRendererInfo;
139 tSDL_GetRendererOutputSize *SDL_GetRendererOutputSize;
140 tSDL_CreateTexture *SDL_CreateTexture;
141 tSDL_CreateTextureFromSurface *SDL_CreateTextureFromSurface;
142 tSDL_QueryTexture *SDL_QueryTexture;
143 tSDL_SetTextureColorMod *SDL_SetTextureColorMod;
144 tSDL_GetTextureColorMod *SDL_GetTextureColorMod;
145 tSDL_SetTextureAlphaMod *SDL_SetTextureAlphaMod;
146 tSDL_GetTextureAlphaMod *SDL_GetTextureAlphaMod;
147 tSDL_SetTextureBlendMode *SDL_SetTextureBlendMode;
148 tSDL_GetTextureBlendMode *SDL_GetTextureBlendMode;
149 tSDL_UpdateTexture *SDL_UpdateTexture;
150 tSDL_LockTexture *SDL_LockTexture;
151 tSDL_UnlockTexture *SDL_UnlockTexture;
152 tSDL_RenderTargetSupported *SDL_RenderTargetSupported;
153 tSDL_SetRenderTarget *SDL_SetRenderTarget;
154 tSDL_GetRenderTarget *SDL_GetRenderTarget;
155 tSDL_RenderSetLogicalSize *SDL_RenderSetLogicalSize;
156 tSDL_RenderGetLogicalSize *SDL_RenderGetLogicalSize;
157 tSDL_RenderSetViewport *SDL_RenderSetViewport;
158 tSDL_RenderGetViewport *SDL_RenderGetViewport;
159 tSDL_RenderSetClipRect *SDL_RenderSetClipRect;
160 tSDL_RenderGetClipRect *SDL_RenderGetClipRect;
161 tSDL_RenderSetScale *SDL_RenderSetScale;
162 tSDL_RenderGetScale *SDL_RenderGetScale;
163 tSDL_SetRenderDrawBlendMode *SDL_SetRenderDrawBlendMode;
164 tSDL_GetRenderDrawBlendMode *SDL_GetRenderDrawBlendMode;
165 tSDL_RenderClear *SDL_RenderClear;
166 tSDL_RenderDrawPoint *SDL_RenderDrawPoint;
167 tSDL_RenderDrawPoints *SDL_RenderDrawPoints;
168 tSDL_RenderDrawLine *SDL_RenderDrawLine;
169 tSDL_RenderDrawLines *SDL_RenderDrawLines;
170 tSDL_RenderDrawRect *SDL_RenderDrawRect;
171 tSDL_RenderDrawRects *SDL_RenderDrawRects;
172 tSDL_RenderFillRect *SDL_RenderFillRect;
173 tSDL_RenderFillRects *SDL_RenderFillRects;
174 tSDL_RenderCopy *SDL_RenderCopy;
175 tSDL_RenderCopyEx *SDL_RenderCopyEx;
176 tSDL_RenderReadPixels *SDL_RenderReadPixels;
177 tSDL_RenderPresent *SDL_RenderPresent;
178 tSDL_DestroyTexture *SDL_DestroyTexture;
179 tSDL_DestroyRenderer *SDL_DestroyRenderer;
180 tSDL_GL_BindTexture *SDL_GL_BindTexture;
181 tSDL_GL_UnbindTexture *SDL_GL_UnbindTexture;
182 tSDL_LoadObject *SDL_LoadObject;
183 tSDL_LoadFunction *SDL_LoadFunction;
184 tSDL_UnloadObject *SDL_UnloadObject;
185 tSDL_ReportAssertion *SDL_ReportAssertion;
186 tSDL_SetAssertionHandler *SDL_SetAssertionHandler;
187 tSDL_GetAssertionReport *SDL_GetAssertionReport;
188 tSDL_ResetAssertionReport *SDL_ResetAssertionReport;
189 tSDL_AtomicTryLock *SDL_AtomicTryLock;
190 tSDL_AtomicLock *SDL_AtomicLock;
191 tSDL_AtomicUnlock *SDL_AtomicUnlock;
192 tSDL_HasIntersection *SDL_HasIntersection;
193 tSDL_IntersectRect *SDL_IntersectRect;
194 tSDL_UnionRect *SDL_UnionRect;
195 tSDL_EnclosePoints *SDL_EnclosePoints;
196 tSDL_IntersectRectAndLine *SDL_IntersectRectAndLine;
197 tSDL_LogSetAllPriority *SDL_LogSetAllPriority;
198 tSDL_LogSetPriority *SDL_LogSetPriority;
199 tSDL_LogGetPriority *SDL_LogGetPriority;
200 tSDL_LogResetPriorities *SDL_LogResetPriorities;
201 tSDL_Log *SDL_Log;
202 tSDL_LogVerbose *SDL_LogVerbose;
203 tSDL_LogDebug *SDL_LogDebug;
204 tSDL_LogInfo *SDL_LogInfo;
205 tSDL_LogWarn *SDL_LogWarn;
206 tSDL_LogError *SDL_LogError;
207 tSDL_LogCritical *SDL_LogCritical;
208 tSDL_LogMessage *SDL_LogMessage;
209 tSDL_LogMessageV *SDL_LogMessageV;
210 tSDL_LogGetOutputFunction *SDL_LogGetOutputFunction;
211 tSDL_LogSetOutputFunction *SDL_LogSetOutputFunction;
212 tSDL_CreateMutex *SDL_CreateMutex;
213 tSDL_LockMutex *SDL_LockMutex;
214 tSDL_TryLockMutex *SDL_TryLockMutex;
215 tSDL_UnlockMutex *SDL_UnlockMutex;
216 tSDL_DestroyMutex *SDL_DestroyMutex;
217 tSDL_CreateSemaphore *SDL_CreateSemaphore;
218 tSDL_DestroySemaphore *SDL_DestroySemaphore;
219 tSDL_SemWait *SDL_SemWait;
220 tSDL_SemTryWait *SDL_SemTryWait;
221 tSDL_SemWaitTimeout *SDL_SemWaitTimeout;
222 tSDL_SemPost *SDL_SemPost;
223 tSDL_SemValue *SDL_SemValue;
224 tSDL_CreateCond *SDL_CreateCond;
225 tSDL_DestroyCond *SDL_DestroyCond;
226 tSDL_CondSignal *SDL_CondSignal;
227 tSDL_CondBroadcast *SDL_CondBroadcast;
228 tSDL_CondWait *SDL_CondWait;
229 tSDL_CondWaitTimeout *SDL_CondWaitTimeout;
230 tSDL_CreateRGBSurface *SDL_CreateRGBSurface;
231 tSDL_CreateRGBSurfaceFrom *SDL_CreateRGBSurfaceFrom;
232 tSDL_FreeSurface *SDL_FreeSurface;
233 tSDL_SetSurfacePalette *SDL_SetSurfacePalette;
234 tSDL_LockSurface *SDL_LockSurface;
235 tSDL_UnlockSurface *SDL_UnlockSurface;
236 tSDL_LoadBMP_RW *SDL_LoadBMP_RW;
237 tSDL_SaveBMP_RW *SDL_SaveBMP_RW;
238 tSDL_SetSurfaceRLE *SDL_SetSurfaceRLE;
239 tSDL_SetColorKey *SDL_SetColorKey;
240 tSDL_GetColorKey *SDL_GetColorKey;
241 tSDL_SetSurfaceColorMod *SDL_SetSurfaceColorMod;
242 tSDL_GetSurfaceColorMod *SDL_GetSurfaceColorMod;
243 tSDL_SetSurfaceAlphaMod *SDL_SetSurfaceAlphaMod;
244 tSDL_GetSurfaceAlphaMod *SDL_GetSurfaceAlphaMod;
245 tSDL_SetSurfaceBlendMode *SDL_SetSurfaceBlendMode;
246 tSDL_GetSurfaceBlendMode *SDL_GetSurfaceBlendMode;
247 tSDL_SetClipRect *SDL_SetClipRect;
248 tSDL_GetClipRect *SDL_GetClipRect;
249 tSDL_ConvertSurface *SDL_ConvertSurface;
250 tSDL_ConvertSurfaceFormat *SDL_ConvertSurfaceFormat;
251 tSDL_ConvertPixels *SDL_ConvertPixels;
252 tSDL_FillRect *SDL_FillRect;
253 tSDL_FillRects *SDL_FillRects;
254 tSDL_UpperBlit *SDL_UpperBlit;
255 tSDL_LowerBlit *SDL_LowerBlit;
256 tSDL_SoftStretch *SDL_SoftStretch;
257 tSDL_UpperBlitScaled *SDL_UpperBlitScaled;
258 tSDL_LowerBlitScaled *SDL_LowerBlitScaled;
259 tSDL_PumpEvents *SDL_PumpEvents;
260 tSDL_PeepEvents *SDL_PeepEvents;
261 tSDL_HasEvent *SDL_HasEvent;
262 tSDL_HasEvents *SDL_HasEvents;
263 tSDL_FlushEvent *SDL_FlushEvent;
264 tSDL_FlushEvents *SDL_FlushEvents;
265 tSDL_PollEvent *SDL_PollEvent;
266 tSDL_WaitEvent *SDL_WaitEvent;
267 tSDL_WaitEventTimeout *SDL_WaitEventTimeout;
268 tSDL_PushEvent *SDL_PushEvent;
269 tSDL_SetEventFilter *SDL_SetEventFilter;
270 tSDL_GetEventFilter *SDL_GetEventFilter;
271 tSDL_AddEventWatch *SDL_AddEventWatch;
272 tSDL_DelEventWatch *SDL_DelEventWatch;
273 tSDL_FilterEvents *SDL_FilterEvents;
274 tSDL_EventState *SDL_EventState;
275 tSDL_RegisterEvents *SDL_RegisterEvents;
276 tSDL_GetMouseFocus *SDL_GetMouseFocus;
277 tSDL_GetMouseState *SDL_GetMouseState;
278 tSDL_GetRelativeMouseState *SDL_GetRelativeMouseState;
279 tSDL_WarpMouseInWindow *SDL_WarpMouseInWindow;
280 tSDL_SetRelativeMouseMode *SDL_SetRelativeMouseMode;
281 tSDL_GetRelativeMouseMode *SDL_GetRelativeMouseMode;
282 tSDL_CreateCursor *SDL_CreateCursor;
283 tSDL_CreateColorCursor *SDL_CreateColorCursor;
284 tSDL_CreateSystemCursor *SDL_CreateSystemCursor;
285 tSDL_SetCursor *SDL_SetCursor;
286 tSDL_GetCursor *SDL_GetCursor;
287 tSDL_GetDefaultCursor *SDL_GetDefaultCursor;
288 tSDL_FreeCursor *SDL_FreeCursor;
289 tSDL_ShowCursor *SDL_ShowCursor;
290 tSDL_GetThreadName *SDL_GetThreadName;
291 tSDL_ThreadID *SDL_ThreadID;
292 tSDL_GetThreadID *SDL_GetThreadID;
293 tSDL_SetThreadPriority *SDL_SetThreadPriority;
294 tSDL_WaitThread *SDL_WaitThread;
295 tSDL_TLSCreate *SDL_TLSCreate;
296 tSDL_TLSGet *SDL_TLSGet;
297 tSDL_TLSSet *SDL_TLSSet;
298 tSDL_GetKeyboardFocus *SDL_GetKeyboardFocus;
299 tSDL_GetKeyboardState *SDL_GetKeyboardState;
300 tSDL_GetModState *SDL_GetModState;
301 tSDL_SetModState *SDL_SetModState;
302 tSDL_GetKeyFromScancode *SDL_GetKeyFromScancode;
303 tSDL_GetScancodeFromKey *SDL_GetScancodeFromKey;
304 tSDL_GetScancodeName *SDL_GetScancodeName;
305 tSDL_GetScancodeFromName *SDL_GetScancodeFromName;
306 tSDL_GetKeyName *SDL_GetKeyName;
307 tSDL_GetKeyFromName *SDL_GetKeyFromName;
308 tSDL_StartTextInput *SDL_StartTextInput;
309 tSDL_IsTextInputActive *SDL_IsTextInputActive;
310 tSDL_StopTextInput *SDL_StopTextInput;
311 tSDL_SetTextInputRect *SDL_SetTextInputRect;
312 tSDL_HasScreenKeyboardSupport *SDL_HasScreenKeyboardSupport;
313 tSDL_IsScreenKeyboardShown *SDL_IsScreenKeyboardShown;
314 tSDL_GameControllerAddMapping *SDL_GameControllerAddMapping;
315 tSDL_GameControllerMappingForGUID *SDL_GameControllerMappingForGUID;
316 tSDL_GameControllerMapping *SDL_GameControllerMapping;
317 tSDL_IsGameController *SDL_IsGameController;
318 tSDL_GameControllerNameForIndex *SDL_GameControllerNameForIndex;
319 tSDL_GameControllerOpen *SDL_GameControllerOpen;
320 tSDL_GameControllerName *SDL_GameControllerName;
321 tSDL_GameControllerGetAttached *SDL_GameControllerGetAttached;
322 tSDL_GameControllerGetJoystick *SDL_GameControllerGetJoystick;
323 tSDL_GameControllerEventState *SDL_GameControllerEventState;
324 tSDL_GameControllerUpdate *SDL_GameControllerUpdate;
325 tSDL_GameControllerGetAxisFromString *SDL_GameControllerGetAxisFromString;
326 tSDL_GameControllerGetButtonFromString *SDL_GameControllerGetButtonFromString;
327 tSDL_GameControllerGetButton *SDL_GameControllerGetButton;
328 tSDL_GameControllerClose *SDL_GameControllerClose;
329 tSDL_GetNumAudioDrivers *SDL_GetNumAudioDrivers;
330 tSDL_GetAudioDriver *SDL_GetAudioDriver;
331 tSDL_AudioInit *SDL_AudioInit;
332 tSDL_AudioQuit *SDL_AudioQuit;
333 tSDL_GetCurrentAudioDriver *SDL_GetCurrentAudioDriver;
334 tSDL_OpenAudio *SDL_OpenAudio;
335 tSDL_GetNumAudioDevices *SDL_GetNumAudioDevices;
336 tSDL_GetAudioDeviceName *SDL_GetAudioDeviceName;
337 tSDL_OpenAudioDevice *SDL_OpenAudioDevice;
338 tSDL_GetAudioStatus *SDL_GetAudioStatus;
339 tSDL_PauseAudio *SDL_PauseAudio;
340 tSDL_PauseAudioDevice *SDL_PauseAudioDevice;
341 tSDL_LoadWAV_RW *SDL_LoadWAV_RW;
342 tSDL_FreeWAV *SDL_FreeWAV;
343 tSDL_BuildAudioCVT *SDL_BuildAudioCVT;
344 tSDL_ConvertAudio *SDL_ConvertAudio;
345 tSDL_MixAudio *SDL_MixAudio;
346 tSDL_MixAudioFormat *SDL_MixAudioFormat;
347 tSDL_LockAudio *SDL_LockAudio;
348 tSDL_LockAudioDevice *SDL_LockAudioDevice;
349 tSDL_UnlockAudio *SDL_UnlockAudio;
350 tSDL_UnlockAudioDevice *SDL_UnlockAudioDevice;
351 tSDL_CloseAudio *SDL_CloseAudio;
352 tSDL_CloseAudioDevice *SDL_CloseAudioDevice;
353 tSDL_GetNumVideoDrivers *SDL_GetNumVideoDrivers;
354 tSDL_GetVideoDriver *SDL_GetVideoDriver;
355 tSDL_VideoInit *SDL_VideoInit;
356 tSDL_VideoQuit *SDL_VideoQuit;
357 tSDL_GetCurrentVideoDriver *SDL_GetCurrentVideoDriver;
358 tSDL_GetNumVideoDisplays *SDL_GetNumVideoDisplays;
359 tSDL_GetDisplayName *SDL_GetDisplayName;
360 tSDL_GetDisplayBounds *SDL_GetDisplayBounds;
361 tSDL_GetNumDisplayModes *SDL_GetNumDisplayModes;
362 tSDL_GetDisplayMode *SDL_GetDisplayMode;
363 tSDL_GetDesktopDisplayMode *SDL_GetDesktopDisplayMode;
364 tSDL_GetCurrentDisplayMode *SDL_GetCurrentDisplayMode;
365 tSDL_GetClosestDisplayMode *SDL_GetClosestDisplayMode;
366 tSDL_GetWindowDisplayIndex *SDL_GetWindowDisplayIndex;
367 tSDL_SetWindowDisplayMode *SDL_SetWindowDisplayMode;
368 tSDL_GetWindowDisplayMode *SDL_GetWindowDisplayMode;
369 tSDL_GetWindowPixelFormat *SDL_GetWindowPixelFormat;
370 tSDL_CreateWindow *SDL_CreateWindow;
371 tSDL_CreateWindowFrom *SDL_CreateWindowFrom;
372 tSDL_GetWindowID *SDL_GetWindowID;
373 tSDL_GetWindowFromID *SDL_GetWindowFromID;
374 tSDL_GetWindowFlags *SDL_GetWindowFlags;
375 tSDL_SetWindowTitle *SDL_SetWindowTitle;
376 tSDL_GetWindowTitle *SDL_GetWindowTitle;
377 tSDL_SetWindowIcon *SDL_SetWindowIcon;
378 tSDL_GetWindowData *SDL_GetWindowData;
379 tSDL_SetWindowPosition *SDL_SetWindowPosition;
380 tSDL_GetWindowPosition *SDL_GetWindowPosition;
381 tSDL_SetWindowSize *SDL_SetWindowSize;
382 tSDL_GetWindowSize *SDL_GetWindowSize;
383 tSDL_SetWindowMinimumSize *SDL_SetWindowMinimumSize;
384 tSDL_GetWindowMinimumSize *SDL_GetWindowMinimumSize;
385 tSDL_SetWindowMaximumSize *SDL_SetWindowMaximumSize;
386 tSDL_GetWindowMaximumSize *SDL_GetWindowMaximumSize;
387 tSDL_SetWindowBordered *SDL_SetWindowBordered;
388 tSDL_ShowWindow *SDL_ShowWindow;
389 tSDL_HideWindow *SDL_HideWindow;
390 tSDL_RaiseWindow *SDL_RaiseWindow;
391 tSDL_MaximizeWindow *SDL_MaximizeWindow;
392 tSDL_MinimizeWindow *SDL_MinimizeWindow;
393 tSDL_RestoreWindow *SDL_RestoreWindow;
394 tSDL_SetWindowFullscreen *SDL_SetWindowFullscreen;
395 tSDL_GetWindowSurface *SDL_GetWindowSurface;
396 tSDL_UpdateWindowSurface *SDL_UpdateWindowSurface;
397 tSDL_UpdateWindowSurfaceRects *SDL_UpdateWindowSurfaceRects;
398 tSDL_SetWindowGrab *SDL_SetWindowGrab;
399 tSDL_GetWindowGrab *SDL_GetWindowGrab;
400 tSDL_SetWindowBrightness *SDL_SetWindowBrightness;
401 tSDL_GetWindowBrightness *SDL_GetWindowBrightness;
402 tSDL_SetWindowGammaRamp *SDL_SetWindowGammaRamp;
403 tSDL_GetWindowGammaRamp *SDL_GetWindowGammaRamp;
404 tSDL_DestroyWindow *SDL_DestroyWindow;
405 tSDL_IsScreenSaverEnabled *SDL_IsScreenSaverEnabled;
406 tSDL_EnableScreenSaver *SDL_EnableScreenSaver;
407 tSDL_DisableScreenSaver *SDL_DisableScreenSaver;
408 tSDL_GL_LoadLibrary *SDL_GL_LoadLibrary;
409 tSDL_GL_GetProcAddress *SDL_GL_GetProcAddress;
410 tSDL_GL_UnloadLibrary *SDL_GL_UnloadLibrary;
411 tSDL_GL_ExtensionSupported *SDL_GL_ExtensionSupported;
412 tSDL_GL_SetAttribute *SDL_GL_SetAttribute;
413 tSDL_GL_GetAttribute *SDL_GL_GetAttribute;
414 tSDL_GL_CreateContext *SDL_GL_CreateContext;
415 tSDL_GL_MakeCurrent *SDL_GL_MakeCurrent;
416 tSDL_GL_GetCurrentContext *SDL_GL_GetCurrentContext;
417 tSDL_GL_SetSwapInterval *SDL_GL_SetSwapInterval;
418 tSDL_GL_GetSwapInterval *SDL_GL_GetSwapInterval;
419 tSDL_GL_SwapWindow *SDL_GL_SwapWindow;
420 tSDL_GL_DeleteContext *SDL_GL_DeleteContext;
421 tSDL_RWFromFile *SDL_RWFromFile;
422 tSDL_RWFromFP *SDL_RWFromFP;
423 tSDL_RWFromFP *SDL_RWFromFP;
424 tSDL_RWFromMem *SDL_RWFromMem;
425 tSDL_RWFromConstMem *SDL_RWFromConstMem;
426 tSDL_AllocRW *SDL_AllocRW;
427 tSDL_FreeRW *SDL_FreeRW;
428 tSDL_ReadU8 *SDL_ReadU8;
429 tSDL_ReadLE16 *SDL_ReadLE16;
430 tSDL_ReadBE16 *SDL_ReadBE16;
431 tSDL_ReadLE32 *SDL_ReadLE32;
432 tSDL_ReadBE32 *SDL_ReadBE32;
433 tSDL_ReadLE64 *SDL_ReadLE64;
434 tSDL_ReadBE64 *SDL_ReadBE64;
435 tSDL_WriteU8 *SDL_WriteU8;
436 tSDL_WriteLE16 *SDL_WriteLE16;
437 tSDL_WriteBE16 *SDL_WriteBE16;
438 tSDL_WriteLE32 *SDL_WriteLE32;
439 tSDL_WriteBE32 *SDL_WriteBE32;
440 tSDL_WriteLE64 *SDL_WriteLE64;
441 tSDL_WriteBE64 *SDL_WriteBE64;
442 tSDL_Init *SDL_Init;
443 tSDL_InitSubSystem *SDL_InitSubSystem;
444 tSDL_QuitSubSystem *SDL_QuitSubSystem;
445 tSDL_WasInit *SDL_WasInit;
446 tSDL_Quit *SDL_Quit;
447 tSDL_GetVersion *SDL_GetVersion;
448 tSDL_GetRevision *SDL_GetRevision;
449 tSDL_GetRevisionNumber *SDL_GetRevisionNumber;
450 tSDL_GetTicks *SDL_GetTicks;
451 tSDL_GetPerformanceCounter *SDL_GetPerformanceCounter;
452 tSDL_GetPerformanceFrequency *SDL_GetPerformanceFrequency;
453 tSDL_Delay *SDL_Delay;
454 tSDL_AddTimer *SDL_AddTimer;
455 tSDL_RemoveTimer *SDL_RemoveTimer;
456 tSDL_SetHintWithPriority *SDL_SetHintWithPriority;
457 tSDL_SetHint *SDL_SetHint;
458 tSDL_GetHint *SDL_GetHint;
459 tSDL_AddHintCallback *SDL_AddHintCallback;
460 tSDL_DelHintCallback *SDL_DelHintCallback;
461 tSDL_ClearHints *SDL_ClearHints;
462 tSDL_NumJoysticks *SDL_NumJoysticks;
463 tSDL_JoystickNameForIndex *SDL_JoystickNameForIndex;
464 tSDL_JoystickOpen *SDL_JoystickOpen;
465 tSDL_JoystickName *SDL_JoystickName;
466 tSDL_JoystickGetDeviceGUID *SDL_JoystickGetDeviceGUID;
467 tSDL_JoystickGetGUID *SDL_JoystickGetGUID;
468 tSDL_JoystickGetGUIDFromString *SDL_JoystickGetGUIDFromString;
469 tSDL_JoystickGetAttached *SDL_JoystickGetAttached;
470 tSDL_JoystickInstanceID *SDL_JoystickInstanceID;
471 tSDL_JoystickNumAxes *SDL_JoystickNumAxes;
472 tSDL_JoystickNumBalls *SDL_JoystickNumBalls;
473 tSDL_JoystickNumHats *SDL_JoystickNumHats;
474 tSDL_JoystickNumButtons *SDL_JoystickNumButtons;
475 tSDL_JoystickUpdate *SDL_JoystickUpdate;
476 tSDL_JoystickEventState *SDL_JoystickEventState;
477 tSDL_JoystickGetAxis *SDL_JoystickGetAxis;
478 tSDL_JoystickGetHat *SDL_JoystickGetHat;
479 tSDL_JoystickGetBall *SDL_JoystickGetBall;
480 tSDL_JoystickGetButton *SDL_JoystickGetButton;
481 tSDL_JoystickClose *SDL_JoystickClose;
482 tSDL_RecordGesture *SDL_RecordGesture;
483 tSDL_SaveAllDollarTemplates *SDL_SaveAllDollarTemplates;
484 tSDL_SaveDollarTemplate *SDL_SaveDollarTemplate;
485 tSDL_LoadDollarTemplates *SDL_LoadDollarTemplates;
486 tSDL_NumHaptics *SDL_NumHaptics;
487 tSDL_HapticName *SDL_HapticName;
488 tSDL_HapticOpen *SDL_HapticOpen;
489 tSDL_HapticOpened *SDL_HapticOpened;
490 tSDL_HapticIndex *SDL_HapticIndex;
491 tSDL_MouseIsHaptic *SDL_MouseIsHaptic;
492 tSDL_HapticOpenFromMouse *SDL_HapticOpenFromMouse;
493 tSDL_JoystickIsHaptic *SDL_JoystickIsHaptic;
494 tSDL_HapticOpenFromJoystick *SDL_HapticOpenFromJoystick;
495 tSDL_HapticClose *SDL_HapticClose;
496 tSDL_HapticNumEffects *SDL_HapticNumEffects;
497 tSDL_HapticNumEffectsPlaying *SDL_HapticNumEffectsPlaying;
498 tSDL_HapticNumAxes *SDL_HapticNumAxes;
499 tSDL_HapticEffectSupported *SDL_HapticEffectSupported;
500 tSDL_HapticNewEffect *SDL_HapticNewEffect;
501 tSDL_HapticUpdateEffect *SDL_HapticUpdateEffect;
502 tSDL_HapticRunEffect *SDL_HapticRunEffect;
503 tSDL_HapticStopEffect *SDL_HapticStopEffect;
504 tSDL_HapticDestroyEffect *SDL_HapticDestroyEffect;
505 tSDL_HapticGetEffectStatus *SDL_HapticGetEffectStatus;
506 tSDL_HapticSetGain *SDL_HapticSetGain;
507 tSDL_HapticSetAutocenter *SDL_HapticSetAutocenter;
508 tSDL_HapticPause *SDL_HapticPause;
509 tSDL_HapticUnpause *SDL_HapticUnpause;
510 tSDL_HapticStopAll *SDL_HapticStopAll;
511 tSDL_HapticRumbleSupported *SDL_HapticRumbleSupported;
512 tSDL_HapticRumbleInit *SDL_HapticRumbleInit;
513 tSDL_HapticRumblePlay *SDL_HapticRumblePlay;
514 tSDL_HapticRumbleStop *SDL_HapticRumbleStop;
515 tSDL_ShowMessageBox *SDL_ShowMessageBox;
516 tSDL_ShowSimpleMessageBox *SDL_ShowSimpleMessageBox;
517 tSDL_PixelFormatEnumToMasks *SDL_PixelFormatEnumToMasks;
518 tSDL_MasksToPixelFormatEnum *SDL_MasksToPixelFormatEnum;
519 tSDL_AllocFormat *SDL_AllocFormat;
520 tSDL_FreeFormat *SDL_FreeFormat;
521 tSDL_AllocPalette *SDL_AllocPalette;
522 tSDL_SetPixelFormatPalette *SDL_SetPixelFormatPalette;
523 tSDL_SetPaletteColors *SDL_SetPaletteColors;
524 tSDL_FreePalette *SDL_FreePalette;
525 tSDL_MapRGB *SDL_MapRGB;
526 tSDL_MapRGBA *SDL_MapRGBA;
527 tSDL_GetRGB *SDL_GetRGB;
528 tSDL_GetRGBA *SDL_GetRGBA;
529 tSDL_CalculateGammaRamp *SDL_CalculateGammaRamp;
530 tSDL_GetPowerInfo *SDL_GetPowerInfo;
531 tSDL_GetCPUCount *SDL_GetCPUCount;
532 tSDL_GetCPUCacheLineSize *SDL_GetCPUCacheLineSize;
533 tSDL_HasRDTSC *SDL_HasRDTSC;
534 tSDL_HasAltiVec *SDL_HasAltiVec;
535 tSDL_HasMMX *SDL_HasMMX;
536 tSDL_Has3DNow *SDL_Has3DNow;
537 tSDL_HasSSE *SDL_HasSSE;
538 tSDL_HasSSE2 *SDL_HasSSE2;
539 tSDL_HasSSE3 *SDL_HasSSE3;
540 tSDL_HasSSE41 *SDL_HasSSE41;
541 tSDL_HasSSE42 *SDL_HasSSE42;
542 tSDL_GetNumTouchDevices *SDL_GetNumTouchDevices;
543 tSDL_GetTouchDevice *SDL_GetTouchDevice;
544 tSDL_GetNumTouchFingers *SDL_GetNumTouchFingers;
545 tSDL_GetTouchFinger *SDL_GetTouchFinger;
546 tSDL_SetError *SDL_SetError;
547 tSDL_GetError *SDL_GetError;
548 tSDL_ClearError *SDL_ClearError;
549 tSDL_Error *SDL_Error;
550 tSDL_SetClipboardText *SDL_SetClipboardText;
551 tSDL_GetClipboardText *SDL_GetClipboardText;
552 tSDL_HasClipboardText *SDL_HasClipboardText;
553 tSDL_GetWindowWMInfo *SDL_GetWindowWMInfo;
554
555 static void sdlewExit(void) {
556   if(lib != NULL) {
557     /*  Ignore errors. */
558     dynamic_library_close(lib);
559     lib = NULL;
560   }
561 }
562
563 /* Implementation function. */
564 int sdlewInit(void) {
565   /* Library paths. */
566 #ifdef _WIN32
567   /* Expected in c:/windows/system or similar, no path needed. */
568   const char *paths[] = {"SDL2.dll", NULL};
569 #elif defined(__APPLE__)
570   /* Default installation path. */
571   const char *paths[] = {"/usr/local/cuda/lib/libSDL2.dylib", NULL};
572 #else
573   const char *paths[] = {"libSDL2.so",
574                          "libSDL2-2.0.so.0",
575                          "libSDL.so",
576                          NULL};
577 #endif
578   static int initialized = 0;
579   static int result = 0;
580   int a, error;
581   SDL_version version;
582
583   if (initialized) {
584     return result;
585   }
586
587   initialized = 1;
588
589   error = atexit(sdlewExit);
590   if (error) {
591     result = SDLEW_ERROR_ATEXIT_FAILED;
592     return result;
593   }
594
595   /* Load library. */
596   for (a = 0; paths[a] != NULL && lib == NULL; ++a) {
597     lib = dynamic_library_open(paths[a]);
598   }
599
600   if (lib == NULL) {
601     result = SDLEW_ERROR_OPEN_FAILED;
602     return result;
603   }
604
605   SDL_LIBRARY_FIND(SDL_GetPlatform);
606   SDL_LIBRARY_FIND(SDL_memcpy);
607 #ifndef HAVE_ALLOCA
608   SDL_LIBRARY_FIND(SDL_malloc);
609 #endif
610   SDL_LIBRARY_FIND(SDL_calloc);
611   SDL_LIBRARY_FIND(SDL_realloc);
612   SDL_LIBRARY_FIND(SDL_free);
613   SDL_LIBRARY_FIND(SDL_getenv);
614   SDL_LIBRARY_FIND(SDL_setenv);
615   SDL_LIBRARY_FIND(SDL_qsort);
616   SDL_LIBRARY_FIND(SDL_abs);
617   SDL_LIBRARY_FIND(SDL_isdigit);
618   SDL_LIBRARY_FIND(SDL_isspace);
619   SDL_LIBRARY_FIND(SDL_toupper);
620   SDL_LIBRARY_FIND(SDL_tolower);
621   SDL_LIBRARY_FIND(SDL_memset);
622   SDL_LIBRARY_FIND(SDL_memmove);
623   SDL_LIBRARY_FIND(SDL_memcmp);
624   SDL_LIBRARY_FIND(SDL_wcslen);
625   SDL_LIBRARY_FIND(SDL_wcslcpy);
626   SDL_LIBRARY_FIND(SDL_wcslcat);
627   SDL_LIBRARY_FIND(SDL_strlen);
628   SDL_LIBRARY_FIND(SDL_strlcpy);
629   SDL_LIBRARY_FIND(SDL_utf8strlcpy);
630   SDL_LIBRARY_FIND(SDL_strlcat);
631   SDL_LIBRARY_FIND(SDL_strdup);
632   SDL_LIBRARY_FIND(SDL_strrev);
633   SDL_LIBRARY_FIND(SDL_strupr);
634   SDL_LIBRARY_FIND(SDL_strlwr);
635   SDL_LIBRARY_FIND(SDL_strchr);
636   SDL_LIBRARY_FIND(SDL_strrchr);
637   SDL_LIBRARY_FIND(SDL_strstr);
638   SDL_LIBRARY_FIND(SDL_itoa);
639   SDL_LIBRARY_FIND(SDL_uitoa);
640   SDL_LIBRARY_FIND(SDL_ltoa);
641   SDL_LIBRARY_FIND(SDL_ultoa);
642   SDL_LIBRARY_FIND(SDL_lltoa);
643   SDL_LIBRARY_FIND(SDL_ulltoa);
644   SDL_LIBRARY_FIND(SDL_atoi);
645   SDL_LIBRARY_FIND(SDL_atof);
646   SDL_LIBRARY_FIND(SDL_strtol);
647   SDL_LIBRARY_FIND(SDL_strtoll);
648   SDL_LIBRARY_FIND(SDL_strtoull);
649   SDL_LIBRARY_FIND(SDL_strtod);
650   SDL_LIBRARY_FIND(SDL_strcmp);
651   SDL_LIBRARY_FIND(SDL_strncmp);
652   SDL_LIBRARY_FIND(SDL_strcasecmp);
653   SDL_LIBRARY_FIND(SDL_strncasecmp);
654   SDL_LIBRARY_FIND(SDL_sscanf);
655   SDL_LIBRARY_FIND(SDL_snprintf);
656   SDL_LIBRARY_FIND(SDL_vsnprintf);
657   SDL_LIBRARY_FIND(SDL_atan);
658   SDL_LIBRARY_FIND(SDL_atan2);
659   SDL_LIBRARY_FIND(SDL_ceil);
660   SDL_LIBRARY_FIND(SDL_copysign);
661   SDL_LIBRARY_FIND(SDL_cos);
662   SDL_LIBRARY_FIND(SDL_cosf);
663   SDL_LIBRARY_FIND(SDL_fabs);
664   SDL_LIBRARY_FIND(SDL_floor);
665   SDL_LIBRARY_FIND(SDL_log);
666   SDL_LIBRARY_FIND(SDL_pow);
667   SDL_LIBRARY_FIND(SDL_scalbn);
668   SDL_LIBRARY_FIND(SDL_sin);
669   SDL_LIBRARY_FIND(SDL_sinf);
670   SDL_LIBRARY_FIND(SDL_sqrt);
671   SDL_LIBRARY_FIND(SDL_iconv_open);
672   SDL_LIBRARY_FIND(SDL_iconv_close);
673   SDL_LIBRARY_FIND(SDL_iconv);
674   SDL_LIBRARY_FIND(SDL_iconv_string);
675   SDL_LIBRARY_FIND(SDL_GetNumRenderDrivers);
676   SDL_LIBRARY_FIND(SDL_GetRenderDriverInfo);
677   SDL_LIBRARY_FIND(SDL_CreateWindowAndRenderer);
678   SDL_LIBRARY_FIND(SDL_CreateRenderer);
679   SDL_LIBRARY_FIND(SDL_CreateSoftwareRenderer);
680   SDL_LIBRARY_FIND(SDL_GetRenderer);
681   SDL_LIBRARY_FIND(SDL_GetRendererInfo);
682   SDL_LIBRARY_FIND(SDL_GetRendererOutputSize);
683   SDL_LIBRARY_FIND(SDL_CreateTexture);
684   SDL_LIBRARY_FIND(SDL_CreateTextureFromSurface);
685   SDL_LIBRARY_FIND(SDL_QueryTexture);
686   SDL_LIBRARY_FIND(SDL_SetTextureColorMod);
687   SDL_LIBRARY_FIND(SDL_GetTextureColorMod);
688   SDL_LIBRARY_FIND(SDL_SetTextureAlphaMod);
689   SDL_LIBRARY_FIND(SDL_GetTextureAlphaMod);
690   SDL_LIBRARY_FIND(SDL_SetTextureBlendMode);
691   SDL_LIBRARY_FIND(SDL_GetTextureBlendMode);
692   SDL_LIBRARY_FIND(SDL_UpdateTexture);
693   SDL_LIBRARY_FIND(SDL_LockTexture);
694   SDL_LIBRARY_FIND(SDL_UnlockTexture);
695   SDL_LIBRARY_FIND(SDL_RenderTargetSupported);
696   SDL_LIBRARY_FIND(SDL_SetRenderTarget);
697   SDL_LIBRARY_FIND(SDL_GetRenderTarget);
698   SDL_LIBRARY_FIND(SDL_RenderSetLogicalSize);
699   SDL_LIBRARY_FIND(SDL_RenderGetLogicalSize);
700   SDL_LIBRARY_FIND(SDL_RenderSetViewport);
701   SDL_LIBRARY_FIND(SDL_RenderGetViewport);
702   SDL_LIBRARY_FIND(SDL_RenderSetClipRect);
703   SDL_LIBRARY_FIND(SDL_RenderGetClipRect);
704   SDL_LIBRARY_FIND(SDL_RenderSetScale);
705   SDL_LIBRARY_FIND(SDL_RenderGetScale);
706   SDL_LIBRARY_FIND(SDL_SetRenderDrawBlendMode);
707   SDL_LIBRARY_FIND(SDL_GetRenderDrawBlendMode);
708   SDL_LIBRARY_FIND(SDL_RenderClear);
709   SDL_LIBRARY_FIND(SDL_RenderDrawPoint);
710   SDL_LIBRARY_FIND(SDL_RenderDrawPoints);
711   SDL_LIBRARY_FIND(SDL_RenderDrawLine);
712   SDL_LIBRARY_FIND(SDL_RenderDrawLines);
713   SDL_LIBRARY_FIND(SDL_RenderDrawRect);
714   SDL_LIBRARY_FIND(SDL_RenderDrawRects);
715   SDL_LIBRARY_FIND(SDL_RenderFillRect);
716   SDL_LIBRARY_FIND(SDL_RenderFillRects);
717   SDL_LIBRARY_FIND(SDL_RenderCopy);
718   SDL_LIBRARY_FIND(SDL_RenderCopyEx);
719   SDL_LIBRARY_FIND(SDL_RenderReadPixels);
720   SDL_LIBRARY_FIND(SDL_RenderPresent);
721   SDL_LIBRARY_FIND(SDL_DestroyTexture);
722   SDL_LIBRARY_FIND(SDL_DestroyRenderer);
723   SDL_LIBRARY_FIND(SDL_GL_BindTexture);
724   SDL_LIBRARY_FIND(SDL_GL_UnbindTexture);
725   SDL_LIBRARY_FIND(SDL_LoadObject);
726   SDL_LIBRARY_FIND(SDL_LoadFunction);
727   SDL_LIBRARY_FIND(SDL_UnloadObject);
728   SDL_LIBRARY_FIND(SDL_ReportAssertion);
729   SDL_LIBRARY_FIND(SDL_SetAssertionHandler);
730   SDL_LIBRARY_FIND(SDL_GetAssertionReport);
731   SDL_LIBRARY_FIND(SDL_ResetAssertionReport);
732   SDL_LIBRARY_FIND(SDL_AtomicTryLock);
733   SDL_LIBRARY_FIND(SDL_AtomicLock);
734   SDL_LIBRARY_FIND(SDL_AtomicUnlock);
735   SDL_LIBRARY_FIND(SDL_HasIntersection);
736   SDL_LIBRARY_FIND(SDL_IntersectRect);
737   SDL_LIBRARY_FIND(SDL_UnionRect);
738   SDL_LIBRARY_FIND(SDL_EnclosePoints);
739   SDL_LIBRARY_FIND(SDL_IntersectRectAndLine);
740   SDL_LIBRARY_FIND(SDL_LogSetAllPriority);
741   SDL_LIBRARY_FIND(SDL_LogSetPriority);
742   SDL_LIBRARY_FIND(SDL_LogGetPriority);
743   SDL_LIBRARY_FIND(SDL_LogResetPriorities);
744   SDL_LIBRARY_FIND(SDL_Log);
745   SDL_LIBRARY_FIND(SDL_LogVerbose);
746   SDL_LIBRARY_FIND(SDL_LogDebug);
747   SDL_LIBRARY_FIND(SDL_LogInfo);
748   SDL_LIBRARY_FIND(SDL_LogWarn);
749   SDL_LIBRARY_FIND(SDL_LogError);
750   SDL_LIBRARY_FIND(SDL_LogCritical);
751   SDL_LIBRARY_FIND(SDL_LogMessage);
752   SDL_LIBRARY_FIND(SDL_LogMessageV);
753   SDL_LIBRARY_FIND(SDL_LogGetOutputFunction);
754   SDL_LIBRARY_FIND(SDL_LogSetOutputFunction);
755   SDL_LIBRARY_FIND(SDL_CreateMutex);
756   SDL_LIBRARY_FIND(SDL_LockMutex);
757   SDL_LIBRARY_FIND(SDL_TryLockMutex);
758   SDL_LIBRARY_FIND(SDL_UnlockMutex);
759   SDL_LIBRARY_FIND(SDL_DestroyMutex);
760   SDL_LIBRARY_FIND(SDL_CreateSemaphore);
761   SDL_LIBRARY_FIND(SDL_DestroySemaphore);
762   SDL_LIBRARY_FIND(SDL_SemWait);
763   SDL_LIBRARY_FIND(SDL_SemTryWait);
764   SDL_LIBRARY_FIND(SDL_SemWaitTimeout);
765   SDL_LIBRARY_FIND(SDL_SemPost);
766   SDL_LIBRARY_FIND(SDL_SemValue);
767   SDL_LIBRARY_FIND(SDL_CreateCond);
768   SDL_LIBRARY_FIND(SDL_DestroyCond);
769   SDL_LIBRARY_FIND(SDL_CondSignal);
770   SDL_LIBRARY_FIND(SDL_CondBroadcast);
771   SDL_LIBRARY_FIND(SDL_CondWait);
772   SDL_LIBRARY_FIND(SDL_CondWaitTimeout);
773   SDL_LIBRARY_FIND(SDL_CreateRGBSurface);
774   SDL_LIBRARY_FIND(SDL_CreateRGBSurfaceFrom);
775   SDL_LIBRARY_FIND(SDL_FreeSurface);
776   SDL_LIBRARY_FIND(SDL_SetSurfacePalette);
777   SDL_LIBRARY_FIND(SDL_LockSurface);
778   SDL_LIBRARY_FIND(SDL_UnlockSurface);
779   SDL_LIBRARY_FIND(SDL_LoadBMP_RW);
780   SDL_LIBRARY_FIND(SDL_SaveBMP_RW);
781   SDL_LIBRARY_FIND(SDL_SetSurfaceRLE);
782   SDL_LIBRARY_FIND(SDL_SetColorKey);
783   SDL_LIBRARY_FIND(SDL_GetColorKey);
784   SDL_LIBRARY_FIND(SDL_SetSurfaceColorMod);
785   SDL_LIBRARY_FIND(SDL_GetSurfaceColorMod);
786   SDL_LIBRARY_FIND(SDL_SetSurfaceAlphaMod);
787   SDL_LIBRARY_FIND(SDL_GetSurfaceAlphaMod);
788   SDL_LIBRARY_FIND(SDL_SetSurfaceBlendMode);
789   SDL_LIBRARY_FIND(SDL_GetSurfaceBlendMode);
790   SDL_LIBRARY_FIND(SDL_SetClipRect);
791   SDL_LIBRARY_FIND(SDL_GetClipRect);
792   SDL_LIBRARY_FIND(SDL_ConvertSurface);
793   SDL_LIBRARY_FIND(SDL_ConvertSurfaceFormat);
794   SDL_LIBRARY_FIND(SDL_ConvertPixels);
795   SDL_LIBRARY_FIND(SDL_FillRect);
796   SDL_LIBRARY_FIND(SDL_FillRects);
797   SDL_LIBRARY_FIND(SDL_UpperBlit);
798   SDL_LIBRARY_FIND(SDL_LowerBlit);
799   SDL_LIBRARY_FIND(SDL_SoftStretch);
800   SDL_LIBRARY_FIND(SDL_UpperBlitScaled);
801   SDL_LIBRARY_FIND(SDL_LowerBlitScaled);
802   SDL_LIBRARY_FIND(SDL_PumpEvents);
803   SDL_LIBRARY_FIND(SDL_PeepEvents);
804   SDL_LIBRARY_FIND(SDL_HasEvent);
805   SDL_LIBRARY_FIND(SDL_HasEvents);
806   SDL_LIBRARY_FIND(SDL_FlushEvent);
807   SDL_LIBRARY_FIND(SDL_FlushEvents);
808   SDL_LIBRARY_FIND(SDL_PollEvent);
809   SDL_LIBRARY_FIND(SDL_WaitEvent);
810   SDL_LIBRARY_FIND(SDL_WaitEventTimeout);
811   SDL_LIBRARY_FIND(SDL_PushEvent);
812   SDL_LIBRARY_FIND(SDL_SetEventFilter);
813   SDL_LIBRARY_FIND(SDL_GetEventFilter);
814   SDL_LIBRARY_FIND(SDL_AddEventWatch);
815   SDL_LIBRARY_FIND(SDL_DelEventWatch);
816   SDL_LIBRARY_FIND(SDL_FilterEvents);
817   SDL_LIBRARY_FIND(SDL_EventState);
818   SDL_LIBRARY_FIND(SDL_RegisterEvents);
819   SDL_LIBRARY_FIND(SDL_GetMouseFocus);
820   SDL_LIBRARY_FIND(SDL_GetMouseState);
821   SDL_LIBRARY_FIND(SDL_GetRelativeMouseState);
822   SDL_LIBRARY_FIND(SDL_WarpMouseInWindow);
823   SDL_LIBRARY_FIND(SDL_SetRelativeMouseMode);
824   SDL_LIBRARY_FIND(SDL_GetRelativeMouseMode);
825   SDL_LIBRARY_FIND(SDL_CreateCursor);
826   SDL_LIBRARY_FIND(SDL_CreateColorCursor);
827   SDL_LIBRARY_FIND(SDL_CreateSystemCursor);
828   SDL_LIBRARY_FIND(SDL_SetCursor);
829   SDL_LIBRARY_FIND(SDL_GetCursor);
830   SDL_LIBRARY_FIND(SDL_GetDefaultCursor);
831   SDL_LIBRARY_FIND(SDL_FreeCursor);
832   SDL_LIBRARY_FIND(SDL_ShowCursor);
833   SDL_LIBRARY_FIND(SDL_GetThreadName);
834   SDL_LIBRARY_FIND(SDL_ThreadID);
835   SDL_LIBRARY_FIND(SDL_GetThreadID);
836   SDL_LIBRARY_FIND(SDL_SetThreadPriority);
837   SDL_LIBRARY_FIND(SDL_WaitThread);
838   SDL_LIBRARY_FIND(SDL_TLSCreate);
839   SDL_LIBRARY_FIND(SDL_TLSGet);
840   SDL_LIBRARY_FIND(SDL_TLSSet);
841   SDL_LIBRARY_FIND(SDL_GetKeyboardFocus);
842   SDL_LIBRARY_FIND(SDL_GetKeyboardState);
843   SDL_LIBRARY_FIND(SDL_GetModState);
844   SDL_LIBRARY_FIND(SDL_SetModState);
845   SDL_LIBRARY_FIND(SDL_GetKeyFromScancode);
846   SDL_LIBRARY_FIND(SDL_GetScancodeFromKey);
847   SDL_LIBRARY_FIND(SDL_GetScancodeName);
848   SDL_LIBRARY_FIND(SDL_GetScancodeFromName);
849   SDL_LIBRARY_FIND(SDL_GetKeyName);
850   SDL_LIBRARY_FIND(SDL_GetKeyFromName);
851   SDL_LIBRARY_FIND(SDL_StartTextInput);
852   SDL_LIBRARY_FIND(SDL_IsTextInputActive);
853   SDL_LIBRARY_FIND(SDL_StopTextInput);
854   SDL_LIBRARY_FIND(SDL_SetTextInputRect);
855   SDL_LIBRARY_FIND(SDL_HasScreenKeyboardSupport);
856   SDL_LIBRARY_FIND(SDL_IsScreenKeyboardShown);
857   SDL_LIBRARY_FIND(SDL_GameControllerAddMapping);
858   SDL_LIBRARY_FIND(SDL_GameControllerMappingForGUID);
859   SDL_LIBRARY_FIND(SDL_GameControllerMapping);
860   SDL_LIBRARY_FIND(SDL_IsGameController);
861   SDL_LIBRARY_FIND(SDL_GameControllerNameForIndex);
862   SDL_LIBRARY_FIND(SDL_GameControllerOpen);
863   SDL_LIBRARY_FIND(SDL_GameControllerName);
864   SDL_LIBRARY_FIND(SDL_GameControllerGetAttached);
865   SDL_LIBRARY_FIND(SDL_GameControllerGetJoystick);
866   SDL_LIBRARY_FIND(SDL_GameControllerEventState);
867   SDL_LIBRARY_FIND(SDL_GameControllerUpdate);
868   SDL_LIBRARY_FIND(SDL_GameControllerGetAxisFromString);
869   SDL_LIBRARY_FIND(SDL_GameControllerGetButtonFromString);
870   SDL_LIBRARY_FIND(SDL_GameControllerGetButton);
871   SDL_LIBRARY_FIND(SDL_GameControllerClose);
872   SDL_LIBRARY_FIND(SDL_GetNumAudioDrivers);
873   SDL_LIBRARY_FIND(SDL_GetAudioDriver);
874   SDL_LIBRARY_FIND(SDL_AudioInit);
875   SDL_LIBRARY_FIND(SDL_AudioQuit);
876   SDL_LIBRARY_FIND(SDL_GetCurrentAudioDriver);
877   SDL_LIBRARY_FIND(SDL_OpenAudio);
878   SDL_LIBRARY_FIND(SDL_GetNumAudioDevices);
879   SDL_LIBRARY_FIND(SDL_GetAudioDeviceName);
880   SDL_LIBRARY_FIND(SDL_OpenAudioDevice);
881   SDL_LIBRARY_FIND(SDL_GetAudioStatus);
882   SDL_LIBRARY_FIND(SDL_PauseAudio);
883   SDL_LIBRARY_FIND(SDL_PauseAudioDevice);
884   SDL_LIBRARY_FIND(SDL_LoadWAV_RW);
885   SDL_LIBRARY_FIND(SDL_FreeWAV);
886   SDL_LIBRARY_FIND(SDL_BuildAudioCVT);
887   SDL_LIBRARY_FIND(SDL_ConvertAudio);
888   SDL_LIBRARY_FIND(SDL_MixAudio);
889   SDL_LIBRARY_FIND(SDL_MixAudioFormat);
890   SDL_LIBRARY_FIND(SDL_LockAudio);
891   SDL_LIBRARY_FIND(SDL_LockAudioDevice);
892   SDL_LIBRARY_FIND(SDL_UnlockAudio);
893   SDL_LIBRARY_FIND(SDL_UnlockAudioDevice);
894   SDL_LIBRARY_FIND(SDL_CloseAudio);
895   SDL_LIBRARY_FIND(SDL_CloseAudioDevice);
896   SDL_LIBRARY_FIND(SDL_GetNumVideoDrivers);
897   SDL_LIBRARY_FIND(SDL_GetVideoDriver);
898   SDL_LIBRARY_FIND(SDL_VideoInit);
899   SDL_LIBRARY_FIND(SDL_VideoQuit);
900   SDL_LIBRARY_FIND(SDL_GetCurrentVideoDriver);
901   SDL_LIBRARY_FIND(SDL_GetNumVideoDisplays);
902   SDL_LIBRARY_FIND(SDL_GetDisplayName);
903   SDL_LIBRARY_FIND(SDL_GetDisplayBounds);
904   SDL_LIBRARY_FIND(SDL_GetNumDisplayModes);
905   SDL_LIBRARY_FIND(SDL_GetDisplayMode);
906   SDL_LIBRARY_FIND(SDL_GetDesktopDisplayMode);
907   SDL_LIBRARY_FIND(SDL_GetCurrentDisplayMode);
908   SDL_LIBRARY_FIND(SDL_GetClosestDisplayMode);
909   SDL_LIBRARY_FIND(SDL_GetWindowDisplayIndex);
910   SDL_LIBRARY_FIND(SDL_SetWindowDisplayMode);
911   SDL_LIBRARY_FIND(SDL_GetWindowDisplayMode);
912   SDL_LIBRARY_FIND(SDL_GetWindowPixelFormat);
913   SDL_LIBRARY_FIND(SDL_CreateWindow);
914   SDL_LIBRARY_FIND(SDL_CreateWindowFrom);
915   SDL_LIBRARY_FIND(SDL_GetWindowID);
916   SDL_LIBRARY_FIND(SDL_GetWindowFromID);
917   SDL_LIBRARY_FIND(SDL_GetWindowFlags);
918   SDL_LIBRARY_FIND(SDL_SetWindowTitle);
919   SDL_LIBRARY_FIND(SDL_GetWindowTitle);
920   SDL_LIBRARY_FIND(SDL_SetWindowIcon);
921   SDL_LIBRARY_FIND(SDL_GetWindowData);
922   SDL_LIBRARY_FIND(SDL_SetWindowPosition);
923   SDL_LIBRARY_FIND(SDL_GetWindowPosition);
924   SDL_LIBRARY_FIND(SDL_SetWindowSize);
925   SDL_LIBRARY_FIND(SDL_GetWindowSize);
926   SDL_LIBRARY_FIND(SDL_SetWindowMinimumSize);
927   SDL_LIBRARY_FIND(SDL_GetWindowMinimumSize);
928   SDL_LIBRARY_FIND(SDL_SetWindowMaximumSize);
929   SDL_LIBRARY_FIND(SDL_GetWindowMaximumSize);
930   SDL_LIBRARY_FIND(SDL_SetWindowBordered);
931   SDL_LIBRARY_FIND(SDL_ShowWindow);
932   SDL_LIBRARY_FIND(SDL_HideWindow);
933   SDL_LIBRARY_FIND(SDL_RaiseWindow);
934   SDL_LIBRARY_FIND(SDL_MaximizeWindow);
935   SDL_LIBRARY_FIND(SDL_MinimizeWindow);
936   SDL_LIBRARY_FIND(SDL_RestoreWindow);
937   SDL_LIBRARY_FIND(SDL_SetWindowFullscreen);
938   SDL_LIBRARY_FIND(SDL_GetWindowSurface);
939   SDL_LIBRARY_FIND(SDL_UpdateWindowSurface);
940   SDL_LIBRARY_FIND(SDL_UpdateWindowSurfaceRects);
941   SDL_LIBRARY_FIND(SDL_SetWindowGrab);
942   SDL_LIBRARY_FIND(SDL_GetWindowGrab);
943   SDL_LIBRARY_FIND(SDL_SetWindowBrightness);
944   SDL_LIBRARY_FIND(SDL_GetWindowBrightness);
945   SDL_LIBRARY_FIND(SDL_SetWindowGammaRamp);
946   SDL_LIBRARY_FIND(SDL_GetWindowGammaRamp);
947   SDL_LIBRARY_FIND(SDL_DestroyWindow);
948   SDL_LIBRARY_FIND(SDL_IsScreenSaverEnabled);
949   SDL_LIBRARY_FIND(SDL_EnableScreenSaver);
950   SDL_LIBRARY_FIND(SDL_DisableScreenSaver);
951   SDL_LIBRARY_FIND(SDL_GL_LoadLibrary);
952   SDL_LIBRARY_FIND(SDL_GL_GetProcAddress);
953   SDL_LIBRARY_FIND(SDL_GL_UnloadLibrary);
954   SDL_LIBRARY_FIND(SDL_GL_ExtensionSupported);
955   SDL_LIBRARY_FIND(SDL_GL_SetAttribute);
956   SDL_LIBRARY_FIND(SDL_GL_GetAttribute);
957   SDL_LIBRARY_FIND(SDL_GL_CreateContext);
958   SDL_LIBRARY_FIND(SDL_GL_MakeCurrent);
959   SDL_LIBRARY_FIND(SDL_GL_GetCurrentContext);
960   SDL_LIBRARY_FIND(SDL_GL_SetSwapInterval);
961   SDL_LIBRARY_FIND(SDL_GL_GetSwapInterval);
962   SDL_LIBRARY_FIND(SDL_GL_SwapWindow);
963   SDL_LIBRARY_FIND(SDL_GL_DeleteContext);
964   SDL_LIBRARY_FIND(SDL_RWFromFile);
965   SDL_LIBRARY_FIND(SDL_RWFromFP);
966   SDL_LIBRARY_FIND(SDL_RWFromFP);
967   SDL_LIBRARY_FIND(SDL_RWFromMem);
968   SDL_LIBRARY_FIND(SDL_RWFromConstMem);
969   SDL_LIBRARY_FIND(SDL_AllocRW);
970   SDL_LIBRARY_FIND(SDL_FreeRW);
971   SDL_LIBRARY_FIND(SDL_ReadU8);
972   SDL_LIBRARY_FIND(SDL_ReadLE16);
973   SDL_LIBRARY_FIND(SDL_ReadBE16);
974   SDL_LIBRARY_FIND(SDL_ReadLE32);
975   SDL_LIBRARY_FIND(SDL_ReadBE32);
976   SDL_LIBRARY_FIND(SDL_ReadLE64);
977   SDL_LIBRARY_FIND(SDL_ReadBE64);
978   SDL_LIBRARY_FIND(SDL_WriteU8);
979   SDL_LIBRARY_FIND(SDL_WriteLE16);
980   SDL_LIBRARY_FIND(SDL_WriteBE16);
981   SDL_LIBRARY_FIND(SDL_WriteLE32);
982   SDL_LIBRARY_FIND(SDL_WriteBE32);
983   SDL_LIBRARY_FIND(SDL_WriteLE64);
984   SDL_LIBRARY_FIND(SDL_WriteBE64);
985   SDL_LIBRARY_FIND(SDL_Init);
986   SDL_LIBRARY_FIND(SDL_InitSubSystem);
987   SDL_LIBRARY_FIND(SDL_QuitSubSystem);
988   SDL_LIBRARY_FIND(SDL_WasInit);
989   SDL_LIBRARY_FIND(SDL_Quit);
990   SDL_LIBRARY_FIND(SDL_GetVersion);
991   SDL_LIBRARY_FIND(SDL_GetRevision);
992   SDL_LIBRARY_FIND(SDL_GetRevisionNumber);
993   SDL_LIBRARY_FIND(SDL_GetTicks);
994   SDL_LIBRARY_FIND(SDL_GetPerformanceCounter);
995   SDL_LIBRARY_FIND(SDL_GetPerformanceFrequency);
996   SDL_LIBRARY_FIND(SDL_Delay);
997   SDL_LIBRARY_FIND(SDL_AddTimer);
998   SDL_LIBRARY_FIND(SDL_RemoveTimer);
999   SDL_LIBRARY_FIND(SDL_SetHintWithPriority);
1000   SDL_LIBRARY_FIND(SDL_SetHint);
1001   SDL_LIBRARY_FIND(SDL_GetHint);
1002   SDL_LIBRARY_FIND(SDL_AddHintCallback);
1003   SDL_LIBRARY_FIND(SDL_DelHintCallback);
1004   SDL_LIBRARY_FIND(SDL_ClearHints);
1005   SDL_LIBRARY_FIND(SDL_NumJoysticks);
1006   SDL_LIBRARY_FIND(SDL_JoystickNameForIndex);
1007   SDL_LIBRARY_FIND(SDL_JoystickOpen);
1008   SDL_LIBRARY_FIND(SDL_JoystickName);
1009   SDL_LIBRARY_FIND(SDL_JoystickGetDeviceGUID);
1010   SDL_LIBRARY_FIND(SDL_JoystickGetGUID);
1011   SDL_LIBRARY_FIND(SDL_JoystickGetGUIDFromString);
1012   SDL_LIBRARY_FIND(SDL_JoystickGetAttached);
1013   SDL_LIBRARY_FIND(SDL_JoystickInstanceID);
1014   SDL_LIBRARY_FIND(SDL_JoystickNumAxes);
1015   SDL_LIBRARY_FIND(SDL_JoystickNumBalls);
1016   SDL_LIBRARY_FIND(SDL_JoystickNumHats);
1017   SDL_LIBRARY_FIND(SDL_JoystickNumButtons);
1018   SDL_LIBRARY_FIND(SDL_JoystickUpdate);
1019   SDL_LIBRARY_FIND(SDL_JoystickEventState);
1020   SDL_LIBRARY_FIND(SDL_JoystickGetAxis);
1021   SDL_LIBRARY_FIND(SDL_JoystickGetHat);
1022   SDL_LIBRARY_FIND(SDL_JoystickGetBall);
1023   SDL_LIBRARY_FIND(SDL_JoystickGetButton);
1024   SDL_LIBRARY_FIND(SDL_JoystickClose);
1025   SDL_LIBRARY_FIND(SDL_RecordGesture);
1026   SDL_LIBRARY_FIND(SDL_SaveAllDollarTemplates);
1027   SDL_LIBRARY_FIND(SDL_SaveDollarTemplate);
1028   SDL_LIBRARY_FIND(SDL_LoadDollarTemplates);
1029   SDL_LIBRARY_FIND(SDL_NumHaptics);
1030   SDL_LIBRARY_FIND(SDL_HapticName);
1031   SDL_LIBRARY_FIND(SDL_HapticOpen);
1032   SDL_LIBRARY_FIND(SDL_HapticOpened);
1033   SDL_LIBRARY_FIND(SDL_HapticIndex);
1034   SDL_LIBRARY_FIND(SDL_MouseIsHaptic);
1035   SDL_LIBRARY_FIND(SDL_HapticOpenFromMouse);
1036   SDL_LIBRARY_FIND(SDL_JoystickIsHaptic);
1037   SDL_LIBRARY_FIND(SDL_HapticOpenFromJoystick);
1038   SDL_LIBRARY_FIND(SDL_HapticClose);
1039   SDL_LIBRARY_FIND(SDL_HapticNumEffects);
1040   SDL_LIBRARY_FIND(SDL_HapticNumEffectsPlaying);
1041   SDL_LIBRARY_FIND(SDL_HapticNumAxes);
1042   SDL_LIBRARY_FIND(SDL_HapticEffectSupported);
1043   SDL_LIBRARY_FIND(SDL_HapticNewEffect);
1044   SDL_LIBRARY_FIND(SDL_HapticUpdateEffect);
1045   SDL_LIBRARY_FIND(SDL_HapticRunEffect);
1046   SDL_LIBRARY_FIND(SDL_HapticStopEffect);
1047   SDL_LIBRARY_FIND(SDL_HapticDestroyEffect);
1048   SDL_LIBRARY_FIND(SDL_HapticGetEffectStatus);
1049   SDL_LIBRARY_FIND(SDL_HapticSetGain);
1050   SDL_LIBRARY_FIND(SDL_HapticSetAutocenter);
1051   SDL_LIBRARY_FIND(SDL_HapticPause);
1052   SDL_LIBRARY_FIND(SDL_HapticUnpause);
1053   SDL_LIBRARY_FIND(SDL_HapticStopAll);
1054   SDL_LIBRARY_FIND(SDL_HapticRumbleSupported);
1055   SDL_LIBRARY_FIND(SDL_HapticRumbleInit);
1056   SDL_LIBRARY_FIND(SDL_HapticRumblePlay);
1057   SDL_LIBRARY_FIND(SDL_HapticRumbleStop);
1058   SDL_LIBRARY_FIND(SDL_ShowMessageBox);
1059   SDL_LIBRARY_FIND(SDL_ShowSimpleMessageBox);
1060   SDL_LIBRARY_FIND(SDL_PixelFormatEnumToMasks);
1061   SDL_LIBRARY_FIND(SDL_MasksToPixelFormatEnum);
1062   SDL_LIBRARY_FIND(SDL_AllocFormat);
1063   SDL_LIBRARY_FIND(SDL_FreeFormat);
1064   SDL_LIBRARY_FIND(SDL_AllocPalette);
1065   SDL_LIBRARY_FIND(SDL_SetPixelFormatPalette);
1066   SDL_LIBRARY_FIND(SDL_SetPaletteColors);
1067   SDL_LIBRARY_FIND(SDL_FreePalette);
1068   SDL_LIBRARY_FIND(SDL_MapRGB);
1069   SDL_LIBRARY_FIND(SDL_MapRGBA);
1070   SDL_LIBRARY_FIND(SDL_GetRGB);
1071   SDL_LIBRARY_FIND(SDL_GetRGBA);
1072   SDL_LIBRARY_FIND(SDL_CalculateGammaRamp);
1073   SDL_LIBRARY_FIND(SDL_GetPowerInfo);
1074   SDL_LIBRARY_FIND(SDL_GetCPUCount);
1075   SDL_LIBRARY_FIND(SDL_GetCPUCacheLineSize);
1076   SDL_LIBRARY_FIND(SDL_HasRDTSC);
1077   SDL_LIBRARY_FIND(SDL_HasAltiVec);
1078   SDL_LIBRARY_FIND(SDL_HasMMX);
1079   SDL_LIBRARY_FIND(SDL_Has3DNow);
1080   SDL_LIBRARY_FIND(SDL_HasSSE);
1081   SDL_LIBRARY_FIND(SDL_HasSSE2);
1082   SDL_LIBRARY_FIND(SDL_HasSSE3);
1083   SDL_LIBRARY_FIND(SDL_HasSSE41);
1084   SDL_LIBRARY_FIND(SDL_HasSSE42);
1085   SDL_LIBRARY_FIND(SDL_GetNumTouchDevices);
1086   SDL_LIBRARY_FIND(SDL_GetTouchDevice);
1087   SDL_LIBRARY_FIND(SDL_GetNumTouchFingers);
1088   SDL_LIBRARY_FIND(SDL_GetTouchFinger);
1089   SDL_LIBRARY_FIND(SDL_SetError);
1090   SDL_LIBRARY_FIND(SDL_GetError);
1091   SDL_LIBRARY_FIND(SDL_ClearError);
1092   SDL_LIBRARY_FIND(SDL_Error);
1093   SDL_LIBRARY_FIND(SDL_SetClipboardText);
1094   SDL_LIBRARY_FIND(SDL_GetClipboardText);
1095   SDL_LIBRARY_FIND(SDL_HasClipboardText);
1096   SDL_LIBRARY_FIND(SDL_GetWindowWMInfo);
1097
1098   if (SDL_GetVersion == NULL) {
1099     result = SDLEW_ERROR_VERSION;
1100   }
1101   else {
1102     SDL_GetVersion(&version);
1103     if(version.major < 2) {
1104       result = SDLEW_ERROR_VERSION;
1105     }
1106     else {
1107       result = SDLEW_SUCCESS;
1108     }
1109   }
1110
1111   return result;
1112 }