shithub: cstory

Download patch

ref: 9948fa8b074e16e382fae89e958b186602d5cd7b
parent: b998719ff1207615b0aca74e76bab2e01ec4ff70
author: Clownacy <Clownacy@users.noreply.github.com>
date: Wed Jul 24 16:20:06 EDT 2019

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.

--- a/src/Backends/Rendering.h
+++ b/src/Backends/Rendering.h
@@ -14,6 +14,7 @@
 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);
--- a/src/Backends/Rendering/OpenGL2.cpp
+++ b/src/Backends/Rendering/OpenGL2.cpp
@@ -71,6 +71,15 @@
 	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;
--- a/src/Backends/Rendering/SDLSurface.cpp
+++ b/src/Backends/Rendering/SDLSurface.cpp
@@ -38,6 +38,11 @@
 		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;
--- a/src/Backends/Rendering/SDLTexture.cpp
+++ b/src/Backends/Rendering/SDLTexture.cpp
@@ -81,6 +81,11 @@
 		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);
--- a/src/Backends/Rendering/Software.cpp
+++ b/src/Backends/Rendering/Software.cpp
@@ -34,6 +34,11 @@
 
 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;
--- a/src/Draw.cpp
+++ b/src/Draw.cpp
@@ -69,6 +69,11 @@
 	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
--- 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 @@
 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);
--- a/src/Main.cpp
+++ b/src/Main.cpp
@@ -256,12 +256,8 @@
 					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 @@
 				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)
 				{
--- 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;