From 7bd6ff861796d8d50eb9eb1f8e59cd81bdf9614f Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 1 Apr 2020 15:44:00 +0100 Subject: [PATCH] Get the window icon working on GLFW3 --- src/Backends/Window/GLFW3-OpenGL3.cpp | 47 ++++++++++++++++++++++----- src/Backends/Window/SDL2-OpenGL3.cpp | 5 ++- 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/Backends/Window/GLFW3-OpenGL3.cpp b/src/Backends/Window/GLFW3-OpenGL3.cpp index 5b869455..8831d3fe 100644 --- a/src/Backends/Window/GLFW3-OpenGL3.cpp +++ b/src/Backends/Window/GLFW3-OpenGL3.cpp @@ -1,18 +1,19 @@ #include "../Window.h" +#include +#include + #ifdef USE_OPENGLES2 #include #else #include "../../../external/glad/include/glad/glad.h" #endif - #include -#include - #include "../../WindowsWrapper.h" #include "../Platform.h" +#include "../../Bitmap.h" #include "../../Resource.h" // Horrible hacks @@ -54,16 +55,44 @@ BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_wid window = glfwCreateWindow(*screen_width, *screen_height, window_title, monitor, NULL); if (window != NULL) - {/* + { #ifndef _WIN32 // On Windows, we use native icons instead (so we can give the taskbar and window separate icons, like the original EXE does) size_t resource_size; const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size); - SDL_RWops *rwops = SDL_RWFromConstMem(resource_data, resource_size); - SDL_Surface *icon_surface = SDL_LoadBMP_RW(rwops, 1); - SDL_SetWindowIcon(window, icon_surface); - SDL_FreeSurface(icon_surface); + + unsigned int width, height; + unsigned char *rgb_pixels = DecodeBitmap(resource_data, resource_size, &width, &height); + + if (rgb_pixels != NULL) + { + unsigned char *rgba_pixels = (unsigned char*)malloc(width * height * 4); + + unsigned char *rgb_pointer = rgb_pixels; + unsigned char *rgba_pointer = rgba_pixels; + + if (rgba_pixels != NULL) + { + for (unsigned int y = 0; y < height; ++y) + { + for (unsigned int x = 0; x < width; ++x) + { + *rgba_pointer++ = *rgb_pointer++; + *rgba_pointer++ = *rgb_pointer++; + *rgba_pointer++ = *rgb_pointer++; + *rgba_pointer++ = 0xFF; + } + } + + GLFWimage glfw_image = {(int)width, (int)height, rgba_pixels}; + glfwSetWindowIcon(window, 1, &glfw_image); + + free(rgba_pixels); + } + + FreeBitmap(rgb_pixels); + } #endif -*/ + glfwMakeContextCurrent(window); diff --git a/src/Backends/Window/SDL2-OpenGL3.cpp b/src/Backends/Window/SDL2-OpenGL3.cpp index 64341c67..57c47ec9 100644 --- a/src/Backends/Window/SDL2-OpenGL3.cpp +++ b/src/Backends/Window/SDL2-OpenGL3.cpp @@ -1,15 +1,14 @@ #include "../Window.h" +#include + #ifdef USE_OPENGLES2 #include #else #include "../../../external/glad/include/glad/glad.h" #endif - #include "SDL.h" -#include - #include "../../WindowsWrapper.h" #include "../../Resource.h"