Guest User

Untitled

a guest
Sep 23rd, 2018
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.06 KB | None | 0 0
  1. import std.stdio;
  2. import std.c.time;
  3.  
  4. import derelict.opengl3.gl3;
  5. import derelict.sdl2.sdl;
  6.  
  7. void main () {
  8.     DerelictGL3.load();
  9.     DerelictSDL2.load();
  10.  
  11.     SDL_Window* mainwindow;
  12.     if (SDL_Init(SDL_INIT_VIDEO) < 0) {
  13.     writeln("SDL_Init failed");
  14.     }
  15.  
  16.     mainwindow = SDL_CreateWindow("SDL OpenGL test",
  17.                   SDL_WINDOWPOS_CENTERED,
  18.                   SDL_WINDOWPOS_CENTERED,
  19.                   512, 512,
  20.                   SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
  21.     if (!mainwindow)
  22.         writeln("Unable to create window");
  23.  
  24.     SDL_GLContext maincontext;
  25.     maincontext = SDL_GL_CreateContext(mainwindow);
  26.  
  27.     SDL_GL_SetSwapInterval(1);
  28.  
  29.     bool quit_triggered = false;
  30.     while (!quit_triggered) {
  31.     glClearColor (0.0, 0.6, 0.8, 1.0);
  32.     glClear (GL_COLOR_BUFFER_BIT);
  33.     SDL_GL_SwapWindow(mainwindow);
  34.  
  35.     SDL_PumpEvents();
  36.     ubyte *state = SDL_GetKeyboardState(null);
  37.     if (state[SDL_SCANCODE_ESCAPE]) {
  38.         quit_triggered = true;
  39.     }
  40.     }
  41.  
  42.     SDL_GL_DeleteContext(maincontext);
  43.     SDL_DestroyWindow(mainwindow);
  44.     SDL_Quit();
  45.  
  46.     return;
  47. }
Add Comment
Please, Sign In to add comment