diff options
Diffstat (limited to 'src/sdl/main.c')
-rw-r--r-- | src/sdl/main.c | 70 |
1 files changed, 62 insertions, 8 deletions
diff --git a/src/sdl/main.c b/src/sdl/main.c index 7240d9a..95597f0 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -32,6 +32,60 @@ draw_moves( } static void +log_renderer_info( + SDL_Renderer * const renderer +) { + SDL_RendererInfo info; + + // get renderer info + if (SDL_GetRendererInfo(renderer, &info)) { + die("SDL_GetRendererInfo(): %s", SDL_GetError()); + } + + // log renderer info + SDL_Log( + "renderer:\n" + " name = \"%s\"\n" + " flags = %u%s%s%s%s\n" + " num_texture_formats = %u\n" + " max_texture_width = %d\n" + " max_texture_height = %d", + info.name, + info.flags, + info.flags & SDL_RENDERER_SOFTWARE ? ", software" : "", + info.flags & SDL_RENDERER_ACCELERATED ? ", accelerated" : "", + info.flags & SDL_RENDERER_PRESENTVSYNC ? ", presentvsync" : "", + info.flags & SDL_RENDERER_TARGETTEXTURE ? ", targettexture" : "", + info.num_texture_formats, + info.max_texture_width, + info.max_texture_height + ); +} + +static void +log_texture_info( + SDL_Texture * const tex +) { + Uint32 format; + int access, w, h; + + // query texture + if (SDL_QueryTexture(tex, &format, &access, &w, &h)) { + die("SDL_QueryTexture(): %s", SDL_GetError()); + } + + // log information + SDL_Log( + "texture:\n" + " format = %u\n" + " access = %d\n" + " width = %d\n" + " height = %d", + format, access, w, h + ); +} + +static void solve_on_error( const char * const err ) { @@ -70,10 +124,12 @@ int main(int argc, char *argv[]) { // create window and renderer SDL_Window *win; SDL_Renderer *renderer; - if (SDL_CreateWindowAndRenderer(800, 600, SDL_RENDERER_ACCELERATED | SDL_WINDOW_RESIZABLE, &win, &renderer)) { + if (SDL_CreateWindowAndRenderer(800, 600, SDL_WINDOW_RESIZABLE, &win, &renderer)) { die("SDL_CreateWindowAndRenderer(): %s", SDL_GetError()); } + log_renderer_info(renderer); + // init draw context draw_ctx_t draw_ctx = { .level_num = &level_num, @@ -81,14 +137,13 @@ int main(int argc, char *argv[]) { .ctx = &ctx, .renderer = renderer, .zoom = &zoom, - .sprites = sprites_init(renderer, sprites_png_path), }; - Uint32 format; - int access, w, h; - if (SDL_QueryTexture(draw_ctx.sprites, &format, &access, &w, &h)) { - die("SDL_QueryTexture(): %s", SDL_GetError()); - } + sprites_init(renderer, sprites_png_path, draw_ctx.sprites); + + log_texture_info(draw_ctx.sprites[0]); + + SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_NONE); bool done = false; SDL_Event ev; @@ -201,7 +256,6 @@ int main(int argc, char *argv[]) { } // fini renderer, window - SDL_DestroyTexture(draw_ctx.sprites); SDL_DestroyRenderer(renderer); SDL_DestroyWindow(win); |