Get the window icon working on GLFW3

This commit is contained in:
Clownacy 2020-04-01 15:44:00 +01:00
parent 6301c01315
commit 7bd6ff8617
2 changed files with 40 additions and 12 deletions

View file

@ -1,18 +1,19 @@
#include "../Window.h" #include "../Window.h"
#include <stddef.h>
#include <stdlib.h>
#ifdef USE_OPENGLES2 #ifdef USE_OPENGLES2
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#else #else
#include "../../../external/glad/include/glad/glad.h" #include "../../../external/glad/include/glad/glad.h"
#endif #endif
#include <GLFW/glfw3.h> #include <GLFW/glfw3.h>
#include <stddef.h>
#include "../../WindowsWrapper.h" #include "../../WindowsWrapper.h"
#include "../Platform.h" #include "../Platform.h"
#include "../../Bitmap.h"
#include "../../Resource.h" #include "../../Resource.h"
// Horrible hacks // 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); window = glfwCreateWindow(*screen_width, *screen_height, window_title, monitor, NULL);
if (window != 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) #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; size_t resource_size;
const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &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); unsigned int width, height;
SDL_SetWindowIcon(window, icon_surface); unsigned char *rgb_pixels = DecodeBitmap(resource_data, resource_size, &width, &height);
SDL_FreeSurface(icon_surface);
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 #endif
*/
glfwMakeContextCurrent(window); glfwMakeContextCurrent(window);

View file

@ -1,15 +1,14 @@
#include "../Window.h" #include "../Window.h"
#include <stddef.h>
#ifdef USE_OPENGLES2 #ifdef USE_OPENGLES2
#include <GLES2/gl2.h> #include <GLES2/gl2.h>
#else #else
#include "../../../external/glad/include/glad/glad.h" #include "../../../external/glad/include/glad/glad.h"
#endif #endif
#include "SDL.h" #include "SDL.h"
#include <stddef.h>
#include "../../WindowsWrapper.h" #include "../../WindowsWrapper.h"
#include "../../Resource.h" #include "../../Resource.h"