| 46 | } |
| 47 | |
| 48 | SDL_Texture * |
| 49 | LoadTexture(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 | |
| 98 | SDL_bool |
| 99 | DrawComposite(DrawState *s) |
no test coverage detected