Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module zelda.ApplicationWindow;
- import std.string;
- import derelict.opengl3.gl;
- import derelict.sdl2.sdl;
- class ApplicationWindow {
- this() {
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
- m_width = 160 * 3;
- m_height = 144 * 3;
- m_window = SDL_CreateWindow("DZelda", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, m_width, m_height, SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN);
- if(!m_window) {
- throw new Exception(
- format("Error while initializing window: %s", SDL_GetError()));
- }
- m_context = SDL_GL_CreateContext(m_window);
- if(!m_context) {
- throw new Exception(
- format("Error while initializing OpenGL context: %s", SDL_GetError()));
- }
- DerelictGL.reload();
- initOpenGL();
- m_isOpen = true;
- }
- ~this() {
- SDL_DestroyWindow(m_window);
- SDL_GL_DeleteContext(m_context);
- }
- void initOpenGL() {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_TEXTURE_2D);
- }
- void clear() {
- glClear(GL_COLOR_BUFFER_BIT);
- }
- void update() {
- SDL_GL_SwapWindow(m_window);
- }
- bool isOpen() const { return m_isOpen; }
- void close() { m_isOpen = false; }
- private SDL_Window *m_window;
- private SDL_GLContext m_context;
- private bool m_isOpen = false;
- private ushort m_width = 0;
- private ushort m_height = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement