From 45d9158ce14d4132f888c9ca29141700fbe17a04 Mon Sep 17 00:00:00 2001 From: Anne Marije v/d Meer Date: Mon, 12 Nov 2018 11:22:37 +0100 Subject: [PATCH] CHeck for opengl version, minimum require 3, and only enable debugging when supported --- src/Main.cpp | 47 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 9 deletions(-) diff --git a/src/Main.cpp b/src/Main.cpp index 13af30b..d277130 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -122,11 +122,18 @@ ST::string s_rootPath; imVfs s_vfs; SDL_Window *s_display; - +SDL_GLContext s_glContext FILE *s_logFile = stderr; PFNGLCOMPRESSEDTEXIMAGE2DARBPROC GLX_CompressedTexImage2D = 0; +void cleanup() { + SDL_GL_DeleteContext(s_glContext); + SDL_DestroyWindow(s_display); + + SDL_Quit(); +} + #ifdef WIN32 int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) @@ -242,11 +249,21 @@ int main(int argc, char *argv[]) // Create a window for the game +<<<<<<< HEAD s_display = SDL_CreateWindow("imaginaryMyst Alpha", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, winWidth, winHeight, SDL_WINDOW_OPENGL); SDL_GLContext glContext = SDL_GL_CreateContext(s_display); +======= + s_display = SDL_CreateWindow("imaginaryMyst Alpha", + SDL_WINDOWPOS_CENTERED, + SDL_WINDOWPOS_CENTERED, + winWidth, winHeight, + SDL_WINDOW_OPENGL); + s_glContext = SDL_GL_CreateContext(s_display); + +>>>>>>> CHeck for opengl version, minimum require 3, and only enable debugging when supported glewExperimental = true; if (glewInit() != GLEW_OK) { fprintf(stderr, "Failed to initialize GLEW\n"); @@ -254,10 +271,25 @@ int main(int argc, char *argv[]) } glEnable(GL_DEBUG_OUTPUT); glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS); - glDebugMessageCallback(openglCallbackFunction, nullptr); - glDebugMessageControl( - GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true - ); + + int glMajorVersion; + int glMinorVersion; + SDL_GL_GetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, &glMajorVersion); + SDL_GL_GetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, &glMinorVersion); + + if (glMajorVersion < 3) { + fprintf(stderr, + "ERROR OoenGL version too low, only OpenGL 3 or higher are supported. Opengl version detected %d.%d.", + glMajorVersion, glMinorVersion); + cleanup(); + return 1; + } + if (glMajorVersion > 4 || (glMajorVersion == 4 && glMinorVersion >= 3)) { + glDebugMessageCallback(openglCallbackFunction, nullptr); + glDebugMessageControl( + GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, true + ); + } glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); @@ -304,9 +336,6 @@ int main(int argc, char *argv[]) SDL_GL_SwapWindow(s_display); SDL_Delay(3000); - SDL_GL_DeleteContext(glContext); - SDL_DestroyWindow(s_display); - - SDL_Quit(); +cleanup(); return 0; }