Advertisement
Guest User

Untitled

a guest
Oct 3rd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.39 KB | None | 0 0
  1. import std.stdio;
  2. import derelict.sdl2.sdl;
  3.  
  4.  
  5.  
  6. void main()
  7. {
  8.     DerelictSDL2.load();
  9.  
  10.     SDL_Window* window = null;
  11.     SDL_Surface* screenSurface = null;
  12.  
  13.     if(init(window, screenSurface)) {
  14.             SDL_UpdateWindowSurface(window);
  15.  
  16.             SDL_Delay(2000);
  17.     }
  18.  
  19.    
  20.  
  21.    
  22.        
  23.     if(close(window, screenSurface)) writeln("Success.");
  24.    
  25. }
  26.  
  27. bool init(ref SDL_Window* window, ref SDL_Surface* screenSurface) {
  28.     if( SDL_Init( SDL_INIT_VIDEO ) < 0 ) {
  29.         writefln( "SDL could not initialize! SDL_Error: %s", SDL_GetError());
  30.         return false;
  31.     }
  32.     Screen screen;
  33.     window = SDL_CreateWindow( "SDL Tutorial", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
  34.                                 screen.width, screen.height, SDL_WINDOW_SHOWN);
  35.     if(!window) {
  36.         writeln("Failed to open window. SDL error : %s", SDL_GetError());
  37.         return false;
  38.     } else {
  39.         screenSurface = SDL_GetWindowSurface(window);
  40.     }
  41.    
  42.     return true;
  43. }
  44.  
  45.  
  46. bool close(ref SDL_Window* window, ref SDL_Surface* screenSurface) {
  47.     if(screenSurface) {
  48.         SDL_FreeSurface(screenSurface);
  49.         screenSurface = null;
  50.     }
  51.     if(window) {
  52.         SDL_DestroyWindow(window);
  53.         window = null;
  54.     }
  55.     SDL_Quit();
  56.  
  57.     return true;
  58. }
  59.  
  60. struct Screen {
  61.         const int width = 640;
  62.         const int height = 480;
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement