Cleanup and fixes
This commit is contained in:
parent
7bd6ff8617
commit
ff70664604
10 changed files with 115 additions and 137 deletions
|
@ -6,6 +6,7 @@ extern BOOL bActive;
|
||||||
|
|
||||||
void PlatformBackend_Init(void);
|
void PlatformBackend_Init(void);
|
||||||
void PlatformBackend_Deinit(void);
|
void PlatformBackend_Deinit(void);
|
||||||
|
void PlatformBackend_PostWindowCreation(void);
|
||||||
BOOL PlatformBackend_GetBasePath(char *string_buffer);
|
BOOL PlatformBackend_GetBasePath(char *string_buffer);
|
||||||
BOOL PlatformBackend_SystemTask(void);
|
BOOL PlatformBackend_SystemTask(void);
|
||||||
void PlatformBackend_ShowMessageBox(const char *title, const char *message);
|
void PlatformBackend_ShowMessageBox(const char *title, const char *message);
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
#include "../Platform.h"
|
#include "../Platform.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <stddef.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
@ -9,16 +11,18 @@
|
||||||
|
|
||||||
#include "../../WindowsWrapper.h"
|
#include "../../WindowsWrapper.h"
|
||||||
|
|
||||||
|
#include "../../Bitmap.h"
|
||||||
#include "../../KeyControl.h"
|
#include "../../KeyControl.h"
|
||||||
#include "../../Main.h"
|
#include "../../Main.h"
|
||||||
#include "../../Organya.h"
|
#include "../../Organya.h"
|
||||||
#include "../../Profile.h"
|
#include "../../Profile.h"
|
||||||
|
#include "../../Resource.h"
|
||||||
|
|
||||||
BOOL bActive = TRUE;
|
BOOL bActive = TRUE;
|
||||||
|
|
||||||
extern GLFWwindow *window;
|
extern GLFWwindow *window;
|
||||||
|
|
||||||
void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
static void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||||
{
|
{
|
||||||
(void)window;
|
(void)window;
|
||||||
(void)scancode;
|
(void)scancode;
|
||||||
|
@ -194,7 +198,7 @@ void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowFocusCallback(GLFWwindow *window, int focused)
|
static void WindowFocusCallback(GLFWwindow *window, int focused)
|
||||||
{
|
{
|
||||||
(void)window;
|
(void)window;
|
||||||
|
|
||||||
|
@ -204,13 +208,11 @@ void WindowFocusCallback(GLFWwindow *window, int focused)
|
||||||
InactiveWindow();
|
InactiveWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowSizeCallback(GLFWwindow *window, int width, int height)
|
static void WindowSizeCallback(GLFWwindow *window, int width, int height)
|
||||||
{
|
{
|
||||||
(void)window;
|
(void)window;
|
||||||
(void)width;
|
|
||||||
(void)height;
|
|
||||||
|
|
||||||
Backend_HandleWindowResize();
|
Backend_HandleWindowResize(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformBackend_Init(void)
|
void PlatformBackend_Init(void)
|
||||||
|
@ -223,6 +225,54 @@ void PlatformBackend_Deinit(void)
|
||||||
glfwTerminate();
|
glfwTerminate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlatformBackend_PostWindowCreation(void)
|
||||||
|
{
|
||||||
|
// Hook callbacks
|
||||||
|
glfwSetKeyCallback(window, KeyCallback);
|
||||||
|
glfwSetWindowFocusCallback(window, WindowFocusCallback);
|
||||||
|
glfwSetWindowSizeCallback(window, WindowSizeCallback);
|
||||||
|
|
||||||
|
// Set up window icon
|
||||||
|
|
||||||
|
// TODO - GLFW_ICON
|
||||||
|
#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);
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
BOOL PlatformBackend_GetBasePath(char *string_buffer)
|
BOOL PlatformBackend_GetBasePath(char *string_buffer)
|
||||||
{
|
{
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
|
@ -10,6 +10,9 @@
|
||||||
#include "../../Main.h"
|
#include "../../Main.h"
|
||||||
#include "../../Organya.h"
|
#include "../../Organya.h"
|
||||||
#include "../../Profile.h"
|
#include "../../Profile.h"
|
||||||
|
#include "../../Resource.h"
|
||||||
|
|
||||||
|
extern SDL_Window *window;
|
||||||
|
|
||||||
BOOL bActive = TRUE;
|
BOOL bActive = TRUE;
|
||||||
|
|
||||||
|
@ -23,6 +26,13 @@ void PlatformBackend_Init(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
SDL_InitSubSystem(SDL_INIT_VIDEO);
|
||||||
|
|
||||||
|
puts("Available SDL2 video drivers:");
|
||||||
|
|
||||||
|
for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
|
||||||
|
puts(SDL_GetVideoDriver(i));
|
||||||
|
|
||||||
|
printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlatformBackend_Deinit(void)
|
void PlatformBackend_Deinit(void)
|
||||||
|
@ -30,6 +40,19 @@ void PlatformBackend_Deinit(void)
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PlatformBackend_PostWindowCreation(void)
|
||||||
|
{
|
||||||
|
// Set up window icon
|
||||||
|
#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);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
BOOL PlatformBackend_GetBasePath(char *string_buffer)
|
BOOL PlatformBackend_GetBasePath(char *string_buffer)
|
||||||
{
|
{
|
||||||
char *base_path = SDL_GetBasePath();
|
char *base_path = SDL_GetBasePath();
|
||||||
|
@ -240,7 +263,7 @@ BOOL PlatformBackend_SystemTask(void)
|
||||||
|
|
||||||
case SDL_WINDOWEVENT_RESIZED:
|
case SDL_WINDOWEVENT_RESIZED:
|
||||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||||
Backend_HandleWindowResize();
|
Backend_HandleWindowResize(event.window.data1, event.window.data2);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,7 +285,7 @@ BOOL PlatformBackend_SystemTask(void)
|
||||||
|
|
||||||
void PlatformBackend_ShowMessageBox(const char *title, const char *message)
|
void PlatformBackend_ShowMessageBox(const char *title, const char *message)
|
||||||
{
|
{
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, NULL);
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, title, message, window);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned long PlatformBackend_GetTicks(void)
|
unsigned long PlatformBackend_GetTicks(void)
|
||||||
|
|
|
@ -23,4 +23,4 @@ void Backend_PrepareToDrawGlyphs(Backend_Surface *destination_surface, const uns
|
||||||
void Backend_DrawGlyph(Backend_Glyph *glyph, long x, long y);
|
void Backend_DrawGlyph(Backend_Glyph *glyph, long x, long y);
|
||||||
void Backend_FlushGlyphs(void);
|
void Backend_FlushGlyphs(void);
|
||||||
void Backend_HandleRenderTargetLoss(void);
|
void Backend_HandleRenderTargetLoss(void);
|
||||||
void Backend_HandleWindowResize(void);
|
void Backend_HandleWindowResize(unsigned int width, unsigned int height);
|
||||||
|
|
|
@ -1029,7 +1029,8 @@ void Backend_HandleRenderTargetLoss(void)
|
||||||
// No problem for us
|
// No problem for us
|
||||||
}
|
}
|
||||||
|
|
||||||
void Backend_HandleWindowResize(void)
|
void Backend_HandleWindowResize(unsigned int width, unsigned int height)
|
||||||
{
|
{
|
||||||
// No problem for us
|
actual_screen_width = width;
|
||||||
|
actual_screen_height = height;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
#include "../Rendering.h"
|
#include "../Rendering.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
#include "../../WindowsWrapper.h"
|
#include "../../WindowsWrapper.h"
|
||||||
|
|
||||||
#include "../../Resource.h"
|
#include "../Platform.h"
|
||||||
|
|
||||||
typedef struct Backend_Surface
|
typedef struct Backend_Surface
|
||||||
{
|
{
|
||||||
|
@ -44,26 +44,10 @@ static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect)
|
||||||
|
|
||||||
Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
|
Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
|
||||||
{
|
{
|
||||||
puts("Available SDL2 video drivers:");
|
|
||||||
|
|
||||||
for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
|
|
||||||
puts(SDL_GetVideoDriver(i));
|
|
||||||
|
|
||||||
printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
|
|
||||||
|
|
||||||
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
|
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
|
||||||
|
|
||||||
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)
|
|
||||||
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);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
||||||
|
|
||||||
|
@ -72,9 +56,15 @@ Backend_Surface* Backend_Init(const char *window_title, int screen_width, int sc
|
||||||
framebuffer.sdlsurface = SDL_CreateRGBSurfaceWithFormat(0, window_sdlsurface->w, window_sdlsurface->h, 0, SDL_PIXELFORMAT_RGB24);
|
framebuffer.sdlsurface = SDL_CreateRGBSurfaceWithFormat(0, window_sdlsurface->w, window_sdlsurface->h, 0, SDL_PIXELFORMAT_RGB24);
|
||||||
|
|
||||||
if (framebuffer.sdlsurface != NULL)
|
if (framebuffer.sdlsurface != NULL)
|
||||||
|
{
|
||||||
|
PlatformBackend_PostWindowCreation();
|
||||||
|
|
||||||
return &framebuffer;
|
return &framebuffer;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (SDLSurface rendering backend)", "Could not create framebuffer surface", window);
|
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (SDLSurface rendering backend)", "Could not create framebuffer surface", window);
|
||||||
|
}
|
||||||
|
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#include "../Rendering.h"
|
#include "../Rendering.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
|
|
||||||
|
@ -11,10 +11,10 @@
|
||||||
|
|
||||||
#include "../../WindowsWrapper.h"
|
#include "../../WindowsWrapper.h"
|
||||||
|
|
||||||
|
#inclide "../Platform.h"
|
||||||
#include "../../Draw.h"
|
#include "../../Draw.h"
|
||||||
#include "../../Ending.h"
|
#include "../../Ending.h"
|
||||||
#include "../../MapName.h"
|
#include "../../MapName.h"
|
||||||
#include "../../Resource.h"
|
|
||||||
#include "../../TextScr.h"
|
#include "../../TextScr.h"
|
||||||
|
|
||||||
typedef struct Backend_Surface
|
typedef struct Backend_Surface
|
||||||
|
@ -116,13 +116,6 @@ static void GlyphBatch_DestroyTexture(SPRITEBATCH_U64 texture_id, void *udata)
|
||||||
|
|
||||||
Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
|
Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
|
||||||
{
|
{
|
||||||
puts("Available SDL2 video drivers:");
|
|
||||||
|
|
||||||
for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
|
|
||||||
puts(SDL_GetVideoDriver(i));
|
|
||||||
|
|
||||||
printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
|
|
||||||
|
|
||||||
puts("Available SDL2 render drivers:");
|
puts("Available SDL2 render drivers:");
|
||||||
|
|
||||||
for (int i = 0; i < SDL_GetNumRenderDrivers(); ++i)
|
for (int i = 0; i < SDL_GetNumRenderDrivers(); ++i)
|
||||||
|
@ -136,15 +129,6 @@ Backend_Surface* Backend_Init(const char *window_title, int screen_width, int sc
|
||||||
|
|
||||||
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)
|
|
||||||
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);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
||||||
|
|
||||||
|
@ -180,6 +164,8 @@ Backend_Surface* Backend_Init(const char *window_title, int screen_width, int sc
|
||||||
config.delete_texture_callback = GlyphBatch_DestroyTexture;
|
config.delete_texture_callback = GlyphBatch_DestroyTexture;
|
||||||
spritebatch_init(&glyph_batcher, &config, NULL);
|
spritebatch_init(&glyph_batcher, &config, NULL);
|
||||||
|
|
||||||
|
PlatformBackend_PostWindowCreation();
|
||||||
|
|
||||||
return &framebuffer;
|
return &framebuffer;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
#include "../Rendering.h"
|
#include "../Rendering.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -9,7 +8,7 @@
|
||||||
|
|
||||||
#include "../../WindowsWrapper.h"
|
#include "../../WindowsWrapper.h"
|
||||||
|
|
||||||
#include "../../Resource.h"
|
#include "../Platform.h"
|
||||||
|
|
||||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||||
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
#define MAX(a, b) ((a) > (b) ? (a) : (b))
|
||||||
|
@ -39,26 +38,10 @@ static Backend_Surface *glyph_destination_surface;
|
||||||
|
|
||||||
Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
|
Backend_Surface* Backend_Init(const char *window_title, int screen_width, int screen_height, BOOL fullscreen)
|
||||||
{
|
{
|
||||||
puts("Available SDL2 video drivers:");
|
|
||||||
|
|
||||||
for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
|
|
||||||
puts(SDL_GetVideoDriver(i));
|
|
||||||
|
|
||||||
printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
|
|
||||||
|
|
||||||
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
|
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, screen_width, screen_height, 0);
|
||||||
|
|
||||||
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)
|
|
||||||
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);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
||||||
|
|
||||||
|
@ -73,18 +56,20 @@ Backend_Surface* Backend_Init(const char *window_title, int screen_width, int sc
|
||||||
framebuffer.height = framebuffer_sdlsurface->h;
|
framebuffer.height = framebuffer_sdlsurface->h;
|
||||||
framebuffer.pitch = framebuffer_sdlsurface->pitch;
|
framebuffer.pitch = framebuffer_sdlsurface->pitch;
|
||||||
|
|
||||||
|
PlatformBackend_PostWindowCreation();
|
||||||
|
|
||||||
return &framebuffer;
|
return &framebuffer;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (software rendering backend)", "Could not create framebuffer surface", window);
|
PlatformBackend_ShowMessageBox("Fatal error (software rendering backend)", "Could not create framebuffer surface");
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (software rendering backend)", "Could not create window", NULL);
|
PlatformBackend_ShowMessageBox("Fatal error (software rendering backend)", "Could not create window");
|
||||||
}
|
}
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
|
@ -13,16 +13,10 @@
|
||||||
#include "../../WindowsWrapper.h"
|
#include "../../WindowsWrapper.h"
|
||||||
|
|
||||||
#include "../Platform.h"
|
#include "../Platform.h"
|
||||||
#include "../../Bitmap.h"
|
|
||||||
#include "../../Resource.h"
|
|
||||||
|
|
||||||
// Horrible hacks
|
// Horrible hacks
|
||||||
GLFWwindow *window;
|
GLFWwindow *window;
|
||||||
|
|
||||||
void KeyCallback(GLFWwindow *window, int key, int scancode, int action, int mods);
|
|
||||||
void WindowFocusCallback(GLFWwindow *window, int focused);
|
|
||||||
void WindowSizeCallback(GLFWwindow *window, int width, int height);
|
|
||||||
|
|
||||||
BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen)
|
BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen)
|
||||||
{
|
{
|
||||||
#ifdef USE_OPENGLES2
|
#ifdef USE_OPENGLES2
|
||||||
|
@ -56,44 +50,6 @@ BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_wid
|
||||||
|
|
||||||
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)
|
|
||||||
size_t resource_size;
|
|
||||||
const unsigned char *resource_data = FindResource("ICON_MINI", "ICON", &resource_size);
|
|
||||||
|
|
||||||
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);
|
glfwMakeContextCurrent(window);
|
||||||
|
|
||||||
#ifndef USE_OPENGLES2
|
#ifndef USE_OPENGLES2
|
||||||
|
@ -103,9 +59,7 @@ BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_wid
|
||||||
if (GLAD_GL_VERSION_3_2)
|
if (GLAD_GL_VERSION_3_2)
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
glfwSetKeyCallback(window, KeyCallback);
|
PlatformBackend_PostWindowCreation();
|
||||||
glfwSetWindowFocusCallback(window, WindowFocusCallback);
|
|
||||||
glfwSetWindowSizeCallback(window, WindowSizeCallback);
|
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#ifndef USE_OPENGLES2
|
#ifndef USE_OPENGLES2
|
||||||
|
|
|
@ -11,20 +11,15 @@
|
||||||
|
|
||||||
#include "../../WindowsWrapper.h"
|
#include "../../WindowsWrapper.h"
|
||||||
|
|
||||||
|
#include "../Platform.h"
|
||||||
#include "../../Resource.h"
|
#include "../../Resource.h"
|
||||||
|
|
||||||
static SDL_Window *window;
|
SDL_Window *window;
|
||||||
|
|
||||||
static SDL_GLContext context;
|
static SDL_GLContext context;
|
||||||
|
|
||||||
BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen)
|
BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, BOOL fullscreen)
|
||||||
{
|
{
|
||||||
puts("Available SDL2 video drivers:");
|
|
||||||
|
|
||||||
for (int i = 0; i < SDL_GetNumVideoDrivers(); ++i)
|
|
||||||
puts(SDL_GetVideoDriver(i));
|
|
||||||
|
|
||||||
printf("Selected SDL2 video driver: %s\n", SDL_GetCurrentVideoDriver());
|
|
||||||
|
|
||||||
#ifdef USE_OPENGLES2
|
#ifdef USE_OPENGLES2
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
|
||||||
|
@ -37,19 +32,10 @@ BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_wid
|
||||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, *screen_width, *screen_height, SDL_WINDOW_OPENGL);
|
window = SDL_CreateWindow(window_title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, *screen_width, *screen_height, SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL);
|
||||||
|
|
||||||
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)
|
|
||||||
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);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (fullscreen)
|
if (fullscreen)
|
||||||
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
|
||||||
|
|
||||||
|
@ -66,37 +52,39 @@ BOOL WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_wid
|
||||||
if (GLAD_GL_VERSION_3_2)
|
if (GLAD_GL_VERSION_3_2)
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
PlatformBackend_PostWindowCreation();
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
#ifndef USE_OPENGLES2
|
#ifndef USE_OPENGLES2
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (OpenGL rendering backend)", "Your system does not support OpenGL 3.2", window);
|
PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Your system does not support OpenGL 3.2");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (OpenGL rendering backend)", "Could not load OpenGL functions", window);
|
PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not load OpenGL functions");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (OpenGL rendering backend)", "SDL_GL_MakeCurrent failed", window);
|
PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "SDL_GL_MakeCurrent failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GL_DeleteContext(context);
|
SDL_GL_DeleteContext(context);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (OpenGL rendering backend)", "Could not create OpenGL context", window);
|
PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create OpenGL context");
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_DestroyWindow(window);
|
SDL_DestroyWindow(window);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_ShowSimpleMessageBox(SDL_MESSAGEBOX_ERROR, "Fatal error (OpenGL rendering backend)", "Could not create window", NULL);
|
PlatformBackend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Could not create window");
|
||||||
}
|
}
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
Loading…
Add table
Reference in a new issue