diff --git a/src/main.c b/src/main.c index 9e88fca..bea2f84 100644 --- a/src/main.c +++ b/src/main.c @@ -175,13 +175,29 @@ static bool initialize(void) { return false; } + /* TODO: recognize cli parameter to turn it on on release */ + /* debug mode _defaults_ to being enabled on debug builds. */ + /* you should be able to enable it at runtime on any build */ +#ifndef NDEBUG + ctx.debug = true; +#else + ctx.debug = false; +#endif + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); + SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); + SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 6); + SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 5); SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0); - SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 8); + SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + if (ctx.debug) + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG); + else + SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_NO_ERROR); + /* init got far enough to create a window */ ctx.window = SDL_CreateWindow("townengine", SDL_WINDOWPOS_CENTERED, @@ -202,11 +218,15 @@ static bool initialize(void) { goto fail; } - SDL_GL_MakeCurrent(ctx.window, ctx.gl_context); - SDL_GL_SetSwapInterval(1); + if (SDL_GL_MakeCurrent(ctx.window, ctx.gl_context)) { + CRY_SDL("GL context binding failed."); + goto fail; + } - int glad_status = gladLoadGL(); - if (glad_status == 0) { + if (SDL_GL_SetSwapInterval(-1)) + SDL_GL_SetSwapInterval(1); + + if (gladLoadGL() == 0) { CRY("Init", "GLAD failed"); goto fail; } @@ -261,14 +281,6 @@ static bool initialize(void) { /* you could change this at runtime if you wanted */ ctx.update_multiplicity = 1; - /* debug mode _defaults_ to being enabled on debug builds. */ - /* you should be able to enable it at runtime on any build */ -#ifndef NDEBUG - ctx.debug = true; -#else - ctx.debug = false; -#endif - /* hook up opengl debugging callback */ if (ctx.debug) { glEnable(GL_DEBUG_OUTPUT);