diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-04-28 23:09:09 -0400 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-04-28 23:09:09 -0400 |
| commit | 9b8a1454f11de3728b2e0dc87d5778bce9761459 (patch) | |
| tree | 22f35dd7e0ff8485562246b1b0978a6fbfb97bc9 /renderer.c | |
| parent | cf72845354b6e0e765b3106ac8b2bc47c6b73712 (diff) | |
| download | volute-9b8a1454f11de3728b2e0dc87d5778bce9761459.zip | |
render image
Diffstat (limited to 'renderer.c')
| -rw-r--r-- | renderer.c | 24 |
1 files changed, 24 insertions, 0 deletions
@@ -178,6 +178,30 @@ r_render(mu_Context *ctx) { SDL_RenderPresent(renderer); } +/* Render an image. Returns non-zero on error. */ +int +r_image(SDL_Surface *img, mu_Rect r) { + SDL_Texture *texture; + SDL_Rect rect; + + texture = SDL_CreateTextureFromSurface(renderer, img); + if (!texture) { + fprintf(stderr, "%s\n", SDL_GetError()); + return 1; + } + + rect = (SDL_Rect) {r.x, r.y, r.w, r.h}; + if (SDL_RenderCopy(renderer, texture, NULL, &rect) != 0) { + fprintf(stderr, "%s\n", SDL_GetError()); + SDL_DestroyTexture(texture); + return 1; + } + + SDL_DestroyTexture(texture); + + return 0; +} + static void clear(void) { if (SDL_SetRenderDrawColor(renderer, bg.r, bg.g, bg.b, bg.a) != 0) { |