MCPcopy Create free account
hub / github.com/RavEngine/RavEngine / LoadSprite

Function LoadSprite

deps/SDL2/test/testsprite2.c:60–115  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60int
61LoadSprite(const char *file)
62{
63 int i;
64 SDL_Surface *temp;
65
66 /* Load the sprite image */
67 temp = SDL_LoadBMP(file);
68 if (temp == NULL) {
69 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
70 return (-1);
71 }
72 sprite_w = temp->w;
73 sprite_h = temp->h;
74
75 /* Set transparent pixel as the pixel at (0,0) */
76 if (temp->format->palette) {
77 SDL_SetColorKey(temp, 1, *(Uint8 *) temp->pixels);
78 } else {
79 switch (temp->format->BitsPerPixel) {
80 case 15:
81 SDL_SetColorKey(temp, 1, (*(Uint16 *) temp->pixels) & 0x00007FFF);
82 break;
83 case 16:
84 SDL_SetColorKey(temp, 1, *(Uint16 *) temp->pixels);
85 break;
86 case 24:
87 SDL_SetColorKey(temp, 1, (*(Uint32 *) temp->pixels) & 0x00FFFFFF);
88 break;
89 case 32:
90 SDL_SetColorKey(temp, 1, *(Uint32 *) temp->pixels);
91 break;
92 }
93 }
94
95 /* Create textures from the image */
96 for (i = 0; i < state->num_windows; ++i) {
97 SDL_Renderer *renderer = state->renderers[i];
98 sprites[i] = SDL_CreateTextureFromSurface(renderer, temp);
99 if (!sprites[i]) {
100 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
101 SDL_FreeSurface(temp);
102 return (-1);
103 }
104 if (SDL_SetTextureBlendMode(sprites[i], blendMode) < 0) {
105 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't set blend mode: %s\n", SDL_GetError());
106 SDL_FreeSurface(temp);
107 SDL_DestroyTexture(sprites[i]);
108 return (-1);
109 }
110 }
111 SDL_FreeSurface(temp);
112
113 /* We're ready to roll. :) */
114 return (0);
115}
116
117void

Callers 1

mainFunction · 0.70

Calls 7

SDL_LogErrorFunction · 0.85
SDL_GetErrorFunction · 0.85
SDL_SetColorKeyFunction · 0.85
SDL_FreeSurfaceFunction · 0.85
SDL_SetTextureBlendModeFunction · 0.85
SDL_DestroyTextureFunction · 0.85

Tested by

no test coverage detected