diff --git a/src/Game.cpp b/src/Game.cpp index 22aecd8..d18fac6 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -50,6 +50,17 @@ Game::Game() log_message << "GLEW " << glewGetString(GLEW_VERSION); sb::Log::log(log_message.str()); glm::ivec2 window_size = configuration()["display"]["dimensions"].get(); + + /* Set these before creating a window (see SDL_GLattr.html) */ + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1); + /* Create a window with dimensions set in the config, centered, and flagged to be usable in OpenGL context */ _window = SDL_CreateWindow( configuration()["display"]["title"].get_ref().c_str(), SDL_WINDOWPOS_CENTERED, @@ -171,16 +182,7 @@ void Game::load_gl_context() SDL_DestroyRenderer(renderer); renderer = nullptr; } -#ifndef __EMSCRIPTEN__ - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE); -#endif - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); - SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8); - SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8); - if ((glcontext = SDL_GL_CreateContext(_window)) == nullptr) + if ((glcontext = SDL_GL_CreateContext(window())) == nullptr) { sb::Log::sdl_error("Could not get GL context"); flag_to_end();