From 9948fa8b074e16e382fae89e958b186602d5cd7b Mon Sep 17 00:00:00 2001 From: Clownacy Date: Wed, 24 Jul 2019 20:20:06 +0100 Subject: [PATCH] Move the SDL_Window creation to the rendering backends Whoops, didn't mean to commit the Main.cpp edit way back when I made the OpenGL 2.1 backend. --- src/Backends/Rendering.h | 1 + src/Backends/Rendering/OpenGL2.cpp | 9 +++++++++ src/Backends/Rendering/SDLSurface.cpp | 5 +++++ src/Backends/Rendering/SDLTexture.cpp | 5 +++++ src/Backends/Rendering/Software.cpp | 5 +++++ src/Draw.cpp | 5 +++++ src/Draw.h | 3 +++ src/Main.cpp | 8 ++------ src/WindowsWrapper.h | 1 + 9 files changed, 36 insertions(+), 6 deletions(-) diff --git a/src/Backends/Rendering.h b/src/Backends/Rendering.h index b3239995..ece37db2 100644 --- a/src/Backends/Rendering.h +++ b/src/Backends/Rendering.h @@ -14,6 +14,7 @@ enum typedef struct Backend_Surface Backend_Surface; typedef struct Backend_Glyph Backend_Glyph; +SDL_Window* Backend_CreateWindow(const char *title, int width, int height); BOOL Backend_Init(SDL_Window *window); void Backend_Deinit(void); void Backend_DrawScreen(void); diff --git a/src/Backends/Rendering/OpenGL2.cpp b/src/Backends/Rendering/OpenGL2.cpp index 4fbd3f69..60a0c9fb 100644 --- a/src/Backends/Rendering/OpenGL2.cpp +++ b/src/Backends/Rendering/OpenGL2.cpp @@ -71,6 +71,15 @@ static GLuint CompileShader(const char *fragment_shader_source) return program_id; } +SDL_Window* Backend_CreateWindow(const char *title, int width, int height) +{ + SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); + SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); + + return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, SDL_WINDOW_OPENGL); +} + BOOL Backend_Init(SDL_Window *p_window) { window = p_window; diff --git a/src/Backends/Rendering/SDLSurface.cpp b/src/Backends/Rendering/SDLSurface.cpp index ec530add..7b0c870e 100644 --- a/src/Backends/Rendering/SDLSurface.cpp +++ b/src/Backends/Rendering/SDLSurface.cpp @@ -38,6 +38,11 @@ static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect) sdl_rect->h = 0; } +SDL_Window* Backend_CreateWindow(const char *title, int width, int height) +{ + return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, 0); +} + BOOL Backend_Init(SDL_Window *p_window) { window = p_window; diff --git a/src/Backends/Rendering/SDLTexture.cpp b/src/Backends/Rendering/SDLTexture.cpp index 748eedf2..de888519 100644 --- a/src/Backends/Rendering/SDLTexture.cpp +++ b/src/Backends/Rendering/SDLTexture.cpp @@ -81,6 +81,11 @@ static void RectToSDLRect(const RECT *rect, SDL_Rect *sdl_rect) sdl_rect->h = 0; } +SDL_Window* Backend_CreateWindow(const char *title, int width, int height) +{ + return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, 0); +} + BOOL Backend_Init(SDL_Window *window) { renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_TARGETTEXTURE); diff --git a/src/Backends/Rendering/Software.cpp b/src/Backends/Rendering/Software.cpp index b159b43d..9ccd5106 100644 --- a/src/Backends/Rendering/Software.cpp +++ b/src/Backends/Rendering/Software.cpp @@ -34,6 +34,11 @@ static SDL_Surface *screen_surface; static Backend_Surface framebuffer; +SDL_Window* Backend_CreateWindow(const char *title, int width, int height) +{ + return SDL_CreateWindow(title, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, width, height, 0); +} + BOOL Backend_Init(SDL_Window *p_window) { window = p_window; diff --git a/src/Draw.cpp b/src/Draw.cpp index cfa8889e..23913f3c 100644 --- a/src/Draw.cpp +++ b/src/Draw.cpp @@ -69,6 +69,11 @@ BOOL Flip_SystemTask(HWND hWnd) return TRUE; } +SDL_Window* CreateWindow(const char *title, int width, int height) +{ + return Backend_CreateWindow(title, width, height); +} + BOOL StartDirectDraw(int lMagnification, int lColourDepth) { (void)lColourDepth; // There's no way I'm supporting a bunch of different colour depths diff --git a/src/Draw.h b/src/Draw.h index e7e537b8..c7791462 100644 --- a/src/Draw.h +++ b/src/Draw.h @@ -1,5 +1,7 @@ #pragma once +#include "SDL.h" + #include "WindowsWrapper.h" #ifndef RGB @@ -53,6 +55,7 @@ struct SURFACE; extern SURFACE surf[SURFACE_ID_MAX]; BOOL Flip_SystemTask(HWND hWnd); +SDL_Window* CreateWindow(const char *title, int width, int height); BOOL StartDirectDraw(int lMagnification, int lColourDepth); void EndDirectDraw(); void ReleaseSurface(int s); diff --git a/src/Main.cpp b/src/Main.cpp index 9d8fb8f4..b2e3f82f 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -256,12 +256,8 @@ int main(int argc, char *argv[]) windowHeight = WINDOW_HEIGHT * 2; } - SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_COMPATIBILITY); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2); - SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1); - // Create window - gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, SDL_WINDOW_OPENGL); + gWindow = CreateWindow(lpWindowName, windowWidth, windowHeight); if (gWindow) { @@ -281,7 +277,7 @@ int main(int argc, char *argv[]) windowHeight = WINDOW_HEIGHT * 2; // Create window - gWindow = SDL_CreateWindow(lpWindowName, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, windowWidth, windowHeight, 0); + gWindow = CreateWindow(lpWindowName, windowWidth, windowHeight); if (gWindow) { diff --git a/src/WindowsWrapper.h b/src/WindowsWrapper.h index ca0d6229..cbac5af0 100644 --- a/src/WindowsWrapper.h +++ b/src/WindowsWrapper.h @@ -5,6 +5,7 @@ // Avoid name collisions #undef DrawText #undef FindResource +#undef CreateWindow #else typedef int HWND;