summaryrefslogtreecommitdiff
path: root/src/gl_context.cpp
blob: 2858e22c4b97c2f1649ee6e23cbf065b83562762 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include "gl_context.hpp"
#include <stdexcept>

namespace bookmouse {

GlContext::GlContext(SdlMainWindow& mainWindow)
{
    m_context = SDL_GL_CreateContext(mainWindow.window());
    if (m_context == nullptr) {
        auto error = SDL_GetError();
        throw std::runtime_error{error};
    }

    auto status = SDL_GL_MakeCurrent(mainWindow.window(), m_context);
    if (status != 0) {
        auto error = SDL_GetError();
        throw std::runtime_error{error};
    }
    status = SDL_GL_SetSwapInterval(1); // Enable vsync
    if (status != 0) {
        auto error = SDL_GetError();
        throw std::runtime_error{error};
    }
}

GlContext::~GlContext()
{
    SDL_GL_DeleteContext(m_context);
}


} // namespace bookmouse