|
@@ -19,47 +19,6 @@ void *scp(void *ptr)
|
|
|
return ptr;
|
|
|
}
|
|
|
|
|
|
-SDL_Surface *surface_from_file(const char *file_path)
|
|
|
-{
|
|
|
- int width, height, n;
|
|
|
- unsigned char *pixels = stbi_load(file_path, &width, &height, &n, STBI_rgb_alpha);
|
|
|
- if (pixels == NULL) {
|
|
|
- fprintf(stderr, "ERROR: could not load file %s: %s\n",
|
|
|
- file_path, stbi_failure_reason());
|
|
|
- exit(1);
|
|
|
- }
|
|
|
-
|
|
|
-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
|
|
|
- const Uint32 rmask = 0xff000000;
|
|
|
- const Uint32 gmask = 0x00ff0000;
|
|
|
- const Uint32 bmask = 0x0000ff00;
|
|
|
- const Uint32 amask = 0x000000ff;
|
|
|
-#else // little endian, like x86
|
|
|
- const Uint32 rmask = 0x000000ff;
|
|
|
- const Uint32 gmask = 0x0000ff00;
|
|
|
- const Uint32 bmask = 0x00ff0000;
|
|
|
- const Uint32 amask = 0xff000000;
|
|
|
-#endif
|
|
|
-
|
|
|
- const int depth = 32;
|
|
|
- const int pitch = 4*width;
|
|
|
-
|
|
|
- return scp(SDL_CreateRGBSurfaceFrom(
|
|
|
- (void*)pixels, width, height, depth, pitch,
|
|
|
- rmask, gmask, bmask, amask));
|
|
|
-}
|
|
|
-
|
|
|
-void set_texture_color(SDL_Texture *texture, Uint32 color)
|
|
|
-{
|
|
|
- scc(SDL_SetTextureColorMod(
|
|
|
- texture,
|
|
|
- (color >> (8 * 0)) & 0xff,
|
|
|
- (color >> (8 * 1)) & 0xff,
|
|
|
- (color >> (8 * 2)) & 0xff));
|
|
|
-
|
|
|
- scc(SDL_SetTextureAlphaMod(texture, (color >> (8 * 3)) & 0xff));
|
|
|
-}
|
|
|
-
|
|
|
Vec2f window_size(SDL_Window *window)
|
|
|
{
|
|
|
int w, h;
|