module platformer; import derelict.sdl.sdl; import derelict.sdl.image; import std.string; import std.stdio; static this() { DerelictSDL.load(); if (SDL_Init(SDL_INIT_EVERYTHING) < 0) { throw new Exception("Failed to initialize SDL: " ~ getSDLError()); } } static ~this() { SDL_Quit(); } void main() { SDL_Surface *screen = SDL_SetVideoMode(640, 480, 32, SDL_HWSURFACE | SDL_DOUBLEBUF); if (screen is null) { throw new Exception("Error when setting video mode."); } const void[] imageData = import("images/background.png"); SDL_RWops *rwop = SDL_RWFromConstMem(imageData.ptr, imageData.length); SDL_Surface *image = IMG_Load_RW(rwop, 0); if(image is null) { throw new Exception("Error when loading image."); } bool running = true; while (running) { SDL_Event event; while(SDL_PollEvent(&event)) { switch(event.type) { case SDL_QUIT: running = false; break; } } SDL_BlitSurface(image, null, screen, null); SDL_Flip(screen); } SDL_FreeSurface(image); } char[] getSDLError() { return toString(SDL_GetError()); }