diff options
Diffstat (limited to 'sources/TZR_Init.c')
-rw-r--r-- | sources/TZR_Init.c | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/sources/TZR_Init.c b/sources/TZR_Init.c index c6e3f7e..586b2cf 100644 --- a/sources/TZR_Init.c +++ b/sources/TZR_Init.c @@ -2,6 +2,7 @@ #include "TZR_globals.h" #include "sdl_error.h" #include <SDL2/SDL.h> +#include <SDL2/SDL_opengl.h> #include <SDL2/SDL_mixer.h> #include <SDL2/SDL_mouse.h> #include <errno.h> @@ -48,17 +49,51 @@ _TZR_Init(const TZR_Config *config) ___tzr_config.width * ___tzr_config.ratio * ___tzr_config.scale, ___tzr_config.height * ___tzr_config.scale, - SDL_WINDOW_RESIZABLE); + SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL); + if (___tzr_window == NULL) { + ___tzr_window = + SDL_CreateWindow(config->title, + SDL_WINDOWPOS_UNDEFINED, + SDL_WINDOWPOS_UNDEFINED, + ___tzr_config.width * ___tzr_config.ratio + * ___tzr_config.scale, + ___tzr_config.height * ___tzr_config.scale, + SDL_WINDOW_RESIZABLE ); + } if (___tzr_window == NULL) return _sdl_error(); +#ifdef TZR_OPENGL + ___tzr_gl_ctx = SDL_GL_CreateContext(___tzr_window); + if (___tzr_gl_ctx == NULL) { + TZR_Log("%s", SDL_GetError()); + ___tzr_config.mipmaps = false; + } else if (___tzr_config.mipmaps) do { + const char *gl_version = (const char *)glGetString(GL_VERSION); + if (gl_version == NULL || strlen(gl_version) < 3) { + ___tzr_config.mipmaps = false; + break; + } + const int major = atoi(gl_version); + const int minor = atoi(gl_version + 2); + if (major < 3) + ___tzr_config.mipmaps = false; + } while (0); +#endif /* TZR_OPENGL */ + #ifdef __EMSCRIPTEN__ + /* TODO: verify than this is unneeded */ ___tzr_renderer = SDL_CreateRenderer(___tzr_window, -1, SDL_RENDERER_SOFTWARE); #else ___tzr_renderer = SDL_CreateRenderer(___tzr_window, -1, SDL_RENDERER_ACCELERATED); -#endif + if (___tzr_renderer == NULL) { + TZR_Log("%s", SDL_GetError()); + ___tzr_renderer = SDL_CreateRenderer(___tzr_window, -1, + SDL_RENDERER_SOFTWARE); + } +#endif /* __EMSCRIPTEN__ */ if (___tzr_renderer == NULL) return _sdl_error(); @@ -107,7 +142,7 @@ _TZR_Init(const TZR_Config *config) ___tzr_config.mixer = false; break; } -#endif +#endif /* TZR_SOLOUD */ } while (0); return 0; |