1 /* 2 ******************************************************************************************* 3 * Dgame (a D game framework) - Copyright (c) Randy Schütt 4 * 5 * This software is provided 'as-is', without any express or implied warranty. 6 * In no event will the authors be held liable for any damages arising from 7 * the use of this software. 8 * 9 * Permission is granted to anyone to use this software for any purpose, 10 * including commercial applications, and to alter it and redistribute it 11 * freely, subject to the following restrictions: 12 * 13 * 1. The origin of this software must not be misrepresented; you must not claim 14 * that you wrote the original software. If you use this software in a product, 15 * an acknowledgment in the product documentation would be appreciated but is 16 * not required. 17 * 18 * 2. Altered source versions must be plainly marked as such, and must not be 19 * misrepresented as being the original software. 20 * 21 * 3. This notice may not be removed or altered from any source distribution. 22 ******************************************************************************************* 23 */ 24 module Dgame.Window.all; 25 26 private { 27 debug import std.stdio : writeln; 28 import std.exception : enforce; 29 import std.conv : to; 30 31 import derelict.sdl2.sdl; 32 import derelict.sdl2.image; 33 import derelict.sdl2.ttf; 34 import derelict.opengl3.gl; 35 } 36 37 public { 38 import Dgame.Window.EventHandler; // imports already Dgame.Window.Event 39 import Dgame.Window.MessageBox; 40 import Dgame.Window.VideoMode; 41 import Dgame.Window.Window; 42 } 43 44 shared static this() { 45 DerelictSDL2.load(); 46 DerelictSDL2Image.load(); 47 DerelictSDL2ttf.load(); 48 DerelictGL.load(); 49 50 // Initialize SDL2 51 if (SDL_Init(SDL_INIT_VIDEO) != 0) 52 throw new Exception("SDL Error: " ~ to!string(SDL_GetError())); 53 54 enum ImgFlags = IMG_INIT_JPG | IMG_INIT_PNG; 55 56 const int initted = IMG_Init(ImgFlags); 57 if ((initted & ImgFlags) != ImgFlags) 58 throw new Exception("IMG_Init: Failed to init required jpg and png support!\nIMG_Init: " 59 ~ to!string(IMG_GetError())); 60 61 if (TTF_Init() < 0) 62 throw new Exception("TTF konnte nicht gestartet werden."); 63 64 enforce(TTF_WasInit() == 1, "SDL TTF wurde nicht korrekt initialisiert."); 65 66 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); 67 SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL, 1); 68 } 69 70 shared static ~this() { 71 debug writeln("quit sdl"); 72 73 // unload the dynamically loaded image libraries 74 IMG_Quit(); 75 // unload the TTF support 76 TTF_Quit(); 77 // Uninitialize SDL2 and exit the program 78 SDL_Quit(); 79 }