set GL attributes before creating a window
This commit is contained in:
parent
ee119ecc7e
commit
21e1e7e707
|
@ -37,7 +37,7 @@ Richard Russell -- richard at rtrussell dot co dot uk
|
||||||
#define M_PI 3.1415926535897932384626433832795
|
#define M_PI 3.1415926535897932384626433832795
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "SDL2/SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
/* Set up for C function definitions, even when using C++ */
|
/* Set up for C function definitions, even when using C++ */
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
19
src/Game.cpp
19
src/Game.cpp
|
@ -50,6 +50,17 @@ Game::Game()
|
||||||
log_message << "GLEW " << glewGetString(GLEW_VERSION);
|
log_message << "GLEW " << glewGetString(GLEW_VERSION);
|
||||||
sb::Log::log(log_message.str());
|
sb::Log::log(log_message.str());
|
||||||
glm::ivec2 window_size = get_configuration()["display"]["dimensions"].get<glm::ivec2>();
|
glm::ivec2 window_size = get_configuration()["display"]["dimensions"].get<glm::ivec2>();
|
||||||
|
|
||||||
|
/* 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 */
|
/* Create a window with dimensions set in the config, centered, and flagged to be usable in OpenGL context */
|
||||||
window = SDL_CreateWindow(
|
window = SDL_CreateWindow(
|
||||||
get_configuration()["display"]["title"].get_ref<const std::string&>().c_str(), SDL_WINDOWPOS_CENTERED,
|
get_configuration()["display"]["title"].get_ref<const std::string&>().c_str(), SDL_WINDOWPOS_CENTERED,
|
||||||
|
@ -59,6 +70,7 @@ Game::Game()
|
||||||
sb::Log::sdl_error("Could not create window");
|
sb::Log::sdl_error("Could not create window");
|
||||||
flag_to_end();
|
flag_to_end();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create an SDL renderer for clearing the screen to black and for logging renderer properties. Destroy renderer
|
/* Create an SDL renderer for clearing the screen to black and for logging renderer properties. Destroy renderer
|
||||||
* when finished.
|
* when finished.
|
||||||
*/
|
*/
|
||||||
|
@ -170,13 +182,6 @@ void Game::load_gl_context()
|
||||||
SDL_DestroyRenderer(renderer);
|
SDL_DestroyRenderer(renderer);
|
||||||
renderer = nullptr;
|
renderer = nullptr;
|
||||||
}
|
}
|
||||||
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);
|
|
||||||
if ((glcontext = SDL_GL_CreateContext(window)) == nullptr)
|
if ((glcontext = SDL_GL_CreateContext(window)) == nullptr)
|
||||||
{
|
{
|
||||||
sb::Log::sdl_error("Could not get GL context");
|
sb::Log::sdl_error("Could not get GL context");
|
||||||
|
|
Loading…
Reference in New Issue