Skip to content

Commit

Permalink
CHeck for opengl version, minimum require 3, and only enable debuggin…
Browse files Browse the repository at this point in the history
…g when supported
  • Loading branch information
Anne Marije v/d Meer committed Nov 12, 2018
1 parent 75ea254 commit 45d9158
Showing 1 changed file with 38 additions and 9 deletions.
47 changes: 38 additions & 9 deletions src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -242,22 +249,47 @@ 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");
return -1;
}
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);
Expand Down Expand Up @@ -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;
}

0 comments on commit 45d9158

Please sign in to comment.