From b1edf540d8ffa8705cd800fc34999931535ad74d Mon Sep 17 00:00:00 2001 From: Lior Halphon Date: Fri, 29 Dec 2017 00:43:19 +0200 Subject: [PATCH] Handle failures to create an OpenGL context better --- SDL/main.c | 10 ++++++++++ SDL/shader.c | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/SDL/main.c b/SDL/main.c index 0641544..d5a569d 100755 --- a/SDL/main.c +++ b/SDL/main.c @@ -450,6 +450,16 @@ usage: SDL_SetWindowMinimumSize(window, 160, 144); SDL_GLContext gl_context = SDL_GL_CreateContext(window); + + GLint major, minor; + glGetIntegerv(GL_MAJOR_VERSION, &major); + glGetIntegerv(GL_MINOR_VERSION, &minor); + + if (major * 0x100 + minor < 0x302) { + SDL_GL_DeleteContext(gl_context); + gl_context = NULL; + } + if (gl_context == NULL) { renderer = SDL_CreateRenderer(window, -1, 0); texture = SDL_CreateTexture(renderer, SDL_GetWindowPixelFormat(window), SDL_TEXTUREACCESS_STREAMING, 160, 144); diff --git a/SDL/shader.c b/SDL/shader.c index 47c02d6..47f5d39 100644 --- a/SDL/shader.c +++ b/SDL/shader.c @@ -65,6 +65,14 @@ static GLuint create_program(const char *vsh, const char *fsh) bool init_shader_with_name(shader_t *shader, const char *name) { + GLint major, minor; + glGetIntegerv(GL_MAJOR_VERSION, &major); + glGetIntegerv(GL_MINOR_VERSION, &minor); + + if (major * 0x100 + minor < 0x302) { + return false; + } + static char master_shader_code[0x801] = {0,}; static char shader_code[0x10001] = {0,}; static char final_shader_code[0x10801] = {0,};