src/App.cpp
// create an OpenGL context for an application window
create an OpenGL context for an application window
create an OpenGL context for an application window
static sdl::GLContext CreateOpenGLContext(SDL_Window* window)
{
    log::info("initializing application OpenGL context");
    sdl::GLContext ctx = sdl::GL_CreateContext(window);
    if (SDL_GL_MakeCurrent(window, ctx) != 0)
    {
        throw std::runtime_error{std::string{"SDL_GL_MakeCurrent failed: "} + SDL_GetError()};
    }
     vsync can feel a little laggy on some systems, but vsync reduces CPU usage
     on *constrained* systems (e.g. laptops, which the majority of users are using)
    if (SDL_GL_SetSwapInterval(-1) != 0)
    {
        SDL_GL_SetSwapInterval(1);
    }
     initialize GLEW
     effectively, enables the OpenGL API used by this application
    if (auto err = glewInit(); err != GLEW_OK)
    {
        std::stringstream ss;
        ss << "glewInit() failed: ";
        ss << glewGetErrorString(err);
        throw std::runtime_error{ss.str()};
    }
     depth testing used to ensure geometry overlaps correctly
    glEnable(GL_DEPTH_TEST);
     MSXAA is used to smooth out the model
    glEnable(GL_MULTISAMPLE);
     all vertices in the render are backface-culled
    glEnable(GL_CULL_FACE);
     print OpenGL information if in debug mode
    log::info(
        "OpenGL initialized: info: %s, %s, (%s), GLSL %s",
        glGetString(GL_VENDOR),
        glGetString(GL_RENDERER),
        glGetString(GL_VERSION),
        glGetString(GL_SHADING_LANGUAGE_VERSION));
    return ctx;
}
static sdl :: GLContext CreateOpenGLContext ( SDL_Window * window ) { log :: info ( " " ) ; sdl :: GLContext ctx = sdl :: GL_CreateContext ( window ) ; if ( SDL_GL_MakeCurrent ( window , ctx ) != 0 ) { throw std :: runtime_error { std :: string { " " } + SDL_GetError ( ) } ; } if ( SDL_GL_SetSwapInterval ( -1 ) != 0 ) { SDL_GL_SetSwapInterval ( 1 ) ; } if ( auto err = glewInit ( ) ; err != GLEW_OK ) { std :: stringstream ss ; ss << " " ; ss << glewGetErrorString ( err ) ; throw std :: runtime_error { ss . str ( ) } ; } glEnable ( GL_DEPTH_TEST ) ; glEnable ( GL_MULTISAMPLE ) ; glEnable ( GL_CULL_FACE ) ; log :: info ( " " , glGetString ( GL_VENDOR ) , glGetString ( GL_RENDERER ) , glGetString ( GL_VERSION ) , glGetString ( GL_SHADING_LANGUAGE_VERSION ) ) ; return ctx ; }
create an OpenGL context for an application window
create an OpenGL context for an application window
// enable the context // enable vsync by default // // vsync can feel a little laggy on some systems, but vsync reduces CPU usage // on *constrained* systems (e.g. laptops, which the majority of users are using) // initialize GLEW // // effectively, enables the OpenGL API used by this application // depth testing used to ensure geometry overlaps correctly // MSXAA is used to smooth out the model // all vertices in the render are backface-culled // print OpenGL information if in debug mode