Advertisement
gnidmoo

Untitled

May 24th, 2015
628
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
D 1.41 KB | None | 0 0
  1. module zelda.ApplicationWindow;
  2.  
  3. import std.string;
  4.  
  5. import derelict.opengl3.gl;
  6.  
  7. import derelict.sdl2.sdl;
  8.  
  9. class ApplicationWindow {
  10.     this() {
  11.         SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
  12.         SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
  13.        
  14.         m_width = 160 * 3;
  15.         m_height = 144 * 3;
  16.        
  17.         m_window = SDL_CreateWindow("DZelda", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_width, m_height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
  18.         if(!m_window) {
  19.             throw new Exception(
  20.                 format("Error while initializing window: %s", SDL_GetError()));
  21.         }
  22.        
  23.         m_context = SDL_GL_CreateContext(m_window);
  24.         if(!m_context) {
  25.             throw new Exception(
  26.                 format("Error while initializing OpenGL context: %s", SDL_GetError()));
  27.         }
  28.        
  29.         DerelictGL.reload();
  30.        
  31.         initOpenGL();
  32.        
  33.         m_isOpen = true;
  34.     }
  35.    
  36.     ~this() {
  37.         SDL_DestroyWindow(m_window);
  38.         SDL_GL_DeleteContext(m_context);
  39.     }
  40.    
  41.     void initOpenGL() {
  42.         glEnable(GL_BLEND);
  43.         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
  44.        
  45.         glEnable(GL_TEXTURE_2D);
  46.     }
  47.    
  48.     void clear() {
  49.         glClear(GL_COLOR_BUFFER_BIT);
  50.     }
  51.    
  52.     void update() {
  53.         SDL_GL_SwapWindow(m_window);
  54.     }
  55.    
  56.     bool isOpen() const { return m_isOpen; }
  57.     void close() { m_isOpen = false; }
  58.    
  59.     private SDL_Window *m_window;
  60.     private SDL_GLContext m_context;
  61.    
  62.     private bool m_isOpen = false;
  63.    
  64.     private ushort m_width = 0;
  65.     private ushort m_height = 0;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement