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

Function LoadTexture

deps/SDL2/test/testrendertarget.c:48–96  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48SDL_Texture *
49LoadTexture(SDL_Renderer *renderer, char *file, SDL_bool transparent)
50{
51 SDL_Surface *temp;
52 SDL_Texture *texture;
53
54 /* Load the sprite image */
55 temp = SDL_LoadBMP(file);
56 if (temp == NULL) {
57 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't load %s: %s", file, SDL_GetError());
58 return NULL;
59 }
60
61 /* Set transparent pixel as the pixel at (0,0) */
62 if (transparent) {
63 if (temp->format->palette) {
64 SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
65 } else {
66 switch (temp->format->BitsPerPixel) {
67 case 15:
68 SDL_SetColorKey(temp, SDL_TRUE,
69 (*(Uint16 *) temp->pixels) & 0x00007FFF);
70 break;
71 case 16:
72 SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
73 break;
74 case 24:
75 SDL_SetColorKey(temp, SDL_TRUE,
76 (*(Uint32 *) temp->pixels) & 0x00FFFFFF);
77 break;
78 case 32:
79 SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
80 break;
81 }
82 }
83 }
84
85 /* Create textures from the image */
86 texture = SDL_CreateTextureFromSurface(renderer, temp);
87 if (!texture) {
88 SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture: %s\n", SDL_GetError());
89 SDL_FreeSurface(temp);
90 return NULL;
91 }
92 SDL_FreeSurface(temp);
93
94 /* We're ready to roll. :) */
95 return texture;
96}
97
98SDL_bool
99DrawComposite(DrawState *s)

Callers 1

mainFunction · 0.70

Calls 5

SDL_LogErrorFunction · 0.85
SDL_GetErrorFunction · 0.85
SDL_SetColorKeyFunction · 0.85
SDL_FreeSurfaceFunction · 0.85

Tested by

no test coverage detected