testspriteminimal: make standalone by embedding icon.bmp

This commit is contained in:
Anonymous Maarten
2023-09-04 21:10:30 +02:00
committed by Anonymous Maarten
parent 2a01f9dcb5
commit 4c3e84897f
3 changed files with 102 additions and 22 deletions

View File

@@ -20,7 +20,8 @@
#include <SDL3/SDL.h>
#include <SDL3/SDL_main.h>
#include "testutils.h"
#include "icon.h"
#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480
@@ -35,6 +36,25 @@ static int sprite_w, sprite_h;
static SDL_Renderer *renderer;
static int done;
static SDL_Texture *CreateTexture(SDL_Renderer *r, unsigned char *data, unsigned int len, int *w, int *h) {
SDL_Texture *texture = NULL;
SDL_Surface *surface;
SDL_RWops *src = SDL_RWFromConstMem(data, len);
if (src) {
surface = SDL_LoadBMP_RW(src, SDL_TRUE);
if (surface) {
/* Treat white as transparent */
SDL_SetSurfaceColorKey(surface, SDL_TRUE, SDL_MapRGB(surface->format, 255, 255, 255));
texture = SDL_CreateTextureFromSurface(r, surface);
*w = surface->w;
*h = surface->h;
SDL_DestroySurface(surface);
}
}
return texture;
}
static void MoveSprites(void)
{
int i;
@@ -111,9 +131,10 @@ int main(int argc, char *argv[])
SDL_Log("SDL_SetWindowTitle: %s", SDL_GetError());
}
sprite = LoadTexture(renderer, "icon.bmp", SDL_TRUE, &sprite_w, &sprite_h);
sprite = CreateTexture(renderer, icon_bmp, icon_bmp_len, &sprite_w, &sprite_h);
if (sprite == NULL) {
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture (%s)", SDL_GetError());
return_code = 3;
goto quit;
}