Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import std.stdio;
- import derelict.sdl2.sdl;
- void main()
- {
- DerelictSDL2.load();
- SDL_Window* window = null;
- SDL_Surface* screenSurface = null;
- if(init(window, screenSurface)) {
- SDL_UpdateWindowSurface(window);
- SDL_Delay(2000);
- }
- if(close(window, screenSurface)) writeln("Success.");
- }
- bool init(ref SDL_Window* window, ref SDL_Surface* screenSurface) {
- if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
- writefln( "SDL could not initialize! SDL_Error: %s", SDL_GetError());
- return false;
- }
- Screen screen;
- window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
- screen.width, screen.height, SDL_WINDOW_SHOWN);
- if(!window) {
- writeln("Failed to open window. SDL error : %s", SDL_GetError());
- return false;
- } else {
- screenSurface = SDL_GetWindowSurface(window);
- }
- return true;
- }
- bool close(ref SDL_Window* window, ref SDL_Surface* screenSurface) {
- if(screenSurface) {
- SDL_FreeSurface(screenSurface);
- screenSurface = null;
- }
- if(window) {
- SDL_DestroyWindow(window);
- window = null;
- }
- SDL_Quit();
- return true;
- }
- struct Screen {
- const int width = 640;
- const int height = 480;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement