diff --git a/icons/512.png b/icons/512.png new file mode 100644 index 0000000..c2803a8 Binary files /dev/null and b/icons/512.png differ diff --git a/src/main/main.cpp b/src/main/main.cpp index 1bceffc..74768bc 100644 --- a/src/main/main.cpp +++ b/src/main/main.cpp @@ -30,6 +30,9 @@ #include "SDL_syswm.h" #endif +#define STB_IMAGE_IMPLEMENTATION +#include "../../lib/rt64/src/contrib/stb/stb_image.h" + extern "C" void init(); /*extern "C"*/ void start(ultramodern::WindowHandle window_handle, const ultramodern::audio_callbacks_t* audio_callbacks, const ultramodern::input_callbacks_t* input_callbacks); @@ -55,10 +58,60 @@ ultramodern::gfx_callbacks_t::gfx_data_t create_gfx() { return {}; } +#if defined(__linux__) +bool SetImageAsIcon(const char* filename, SDL_Window* window) +{ + // Read data + int width, height, bytesPerPixel; + void* data = stbi_load(filename, &width, &height, &bytesPerPixel, 4); + + // Calculate pitch + int pitch; + pitch = width * 4; + pitch = (pitch + 3) & ~3; + + // Setup relevance bitmask + int Rmask, Gmask, Bmask, Amask; + +#if SDL_BYTEORDER == SDL_LIL_ENDIAN + Rmask = 0x000000FF; + Gmask = 0x0000FF00; + Bmask = 0x00FF0000; + Amask = 0xFF000000; +#else + Rmask = 0xFF000000; + Gmask = 0x00FF0000; + Bmask = 0x0000FF00; + Amask = 0x000000FF; +#endif + + SDL_Surface* surface; + if (data != NULL) { + surface = SDL_CreateRGBSurfaceFrom(data, width, height, 32, pitch, Rmask, Gmask, + Bmask, Amask); + } + + if (surface == NULL) { + if (data != NULL) { + stbi_image_free(data); + } + return false; + } else { + SDL_SetWindowIcon(window,surface); + SDL_FreeSurface(surface); + stbi_image_free(data); + return true; + } +} +#endif + SDL_Window* window; ultramodern::WindowHandle create_window(ultramodern::gfx_callbacks_t::gfx_data_t) { window = SDL_CreateWindow("Zelda 64: Recompiled", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1600, 960, SDL_WINDOW_RESIZABLE ); +#if defined(__linux__) + SetImageAsIcon("icons/512.png",window); +#endif if (window == nullptr) { exit_error("Failed to create window: %s\n", SDL_GetError());