Exemple #1
0
/*-------------------------------------
    Render Context initialization
-------------------------------------*/
bool Context::init(const Display& disp, bool useVsync) {
    terminate();

    if (disp.is_running() == false) {
        LS_LOG_ERR("\tAttempted to initialize a render context with no display.\n");
        return false;
    }

    // Attach the OpenGL context to our window handle
    LS_LOG_MSG("Initializing an OpenGL rendering context.");
    pContext = SDL_GL_CreateContext(disp.get_window());

    if (!pContext) {
        LS_LOG_ERR(
            "\tUnable to create a render context through SDL.",
            "\n\t", SDL_GetError(),
            '\n'
            );
        terminate();
        return false;
    }
    LS_LOG_MSG("\tSuccessfully created a basic render context.");

    // Quick setup in order to normalize OpenGL to the display coordinates.
    this->make_current(disp);

    const math::vec2i&& displayRes = disp.get_resolution();
    glViewport(0, 0, displayRes[0], displayRes[1]);
    LS_LOG_GL_ERR();

    // Set the default back buffer color
    const ls::draw::color::color& mgcPnk = ls::draw::color::magenta;
    glClearColor(mgcPnk[0], mgcPnk[1], mgcPnk[2], mgcPnk[3]);
    LS_LOG_GL_ERR();

    glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
    LS_LOG_GL_ERR();

    set_vsync(useVsync);

    LS_LOG_MSG(
        "\tSuccessfully initialized a OpenGL 3.3-compatible render context:"
        "\n\tV-Sync: ", get_vsync()
        );

    LS_LOG_MSG("\tSuccessfully initialized the OpenGL 3.3 render context.\n");

    return true;
}
Exemple #2
0
/*-------------------------------------
    Swap the current display's front and back buffers.
-------------------------------------*/
void Context::flip(const Display& disp) const {
    SDL_GL_SwapWindow(disp.get_window());
}
Exemple #3
0
/*-------------------------------------
    Activate the render context used in this window.
-------------------------------------*/
void Context::make_current(const Display& disp) const {
    SDL_GL_MakeCurrent(disp.get_window(), pContext);
}