mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-03-20 15:51:07 +01:00
test: Add some common code to load test resources
As well as reducing duplication, this lets the tests load their resources from the SDL_GetBasePath() on platforms that support it, which is useful if the tests are compiled along with the rest of SDL and installed below /usr as manual tests, similar to GNOME's installed-tests convention. Thanks to Ozkan Sezer for the OS/2 build glue. Co-authored-by: Ozkan Sezer <sezeroz@gmail.com> Signed-off-by: Simon McVittie <smcv@collabora.com>
This commit is contained in:
committed by
Sam Lantinga
parent
ecf1e15fec
commit
76a7b629bf
@@ -21,6 +21,7 @@
|
||||
#endif
|
||||
|
||||
#include "SDL_test_common.h"
|
||||
#include "testutils.h"
|
||||
|
||||
static SDLTest_CommonState *state;
|
||||
static SDL_bool use_texture = SDL_FALSE;
|
||||
@@ -44,54 +45,19 @@ int
|
||||
LoadSprite(const char *file)
|
||||
{
|
||||
int i;
|
||||
SDL_Surface *temp;
|
||||
|
||||
/* Load the sprite image */
|
||||
temp = SDL_LoadBMP(file);
|
||||
if (temp == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
|
||||
return (-1);
|
||||
}
|
||||
sprite_w = temp->w;
|
||||
sprite_h = temp->h;
|
||||
|
||||
/* Set transparent pixel as the pixel at (0,0) */
|
||||
if (temp->format->palette) {
|
||||
SDL_SetColorKey(temp, 1, *(Uint8 *) temp->pixels);
|
||||
} else {
|
||||
switch (temp->format->BitsPerPixel) {
|
||||
case 15:
|
||||
SDL_SetColorKey(temp, 1, (*(Uint16 *) temp->pixels) & 0x00007FFF);
|
||||
break;
|
||||
case 16:
|
||||
SDL_SetColorKey(temp, 1, *(Uint16 *) temp->pixels);
|
||||
break;
|
||||
case 24:
|
||||
SDL_SetColorKey(temp, 1, (*(Uint32 *) temp->pixels) & 0x00FFFFFF);
|
||||
break;
|
||||
case 32:
|
||||
SDL_SetColorKey(temp, 1, *(Uint32 *) temp->pixels);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Create textures from the image */
|
||||
for (i = 0; i < state->num_windows; ++i) {
|
||||
SDL_Renderer *renderer = state->renderers[i];
|
||||
sprites[i] = SDL_CreateTextureFromSurface(renderer, temp);
|
||||
/* This does the SDL_LoadBMP step repeatedly, but that's OK for test code. */
|
||||
sprites[i] = LoadTexture(state->renderers[i], file, SDL_TRUE, &sprite_w, &sprite_h);
|
||||
if (!sprites[i]) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
|
||||
SDL_FreeSurface(temp);
|
||||
return (-1);
|
||||
}
|
||||
if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
|
||||
SDL_FreeSurface(temp);
|
||||
SDL_DestroyTexture(sprites[i]);
|
||||
return (-1);
|
||||
}
|
||||
}
|
||||
SDL_FreeSurface(temp);
|
||||
|
||||
/* We're ready to roll. :) */
|
||||
return (0);
|
||||
|
||||
Reference in New Issue
Block a user