shithub: cstory

Download patch

ref: 5328426b4b04fa0473afa8b0f009037a9a890264
parent: 9b81f453813dfcd78ef17c04243cf3e517416bfd
author: Cameron Cawley <ccawley2011@gmail.com>
date: Thu Jun 25 13:12:50 EDT 2020

Support using the OpenGL3 renderer with SDL 1.2

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -440,6 +440,8 @@
 elseif(BACKEND_PLATFORM MATCHES "SDL2" AND BACKEND_RENDERER MATCHES "SDLSurface")
 elseif(BACKEND_PLATFORM MATCHES "SDL2" AND BACKEND_RENDERER MATCHES "Software")
 	target_sources(CSE2 PRIVATE "src/Backends/Rendering/Window/Software/SDL2.cpp")
+elseif(BACKEND_PLATFORM MATCHES "SDL1" AND BACKEND_RENDERER MATCHES "OpenGL3")
+	target_sources(CSE2 PRIVATE "src/Backends/Rendering/Window/OpenGL3/SDL1.cpp")
 elseif(BACKEND_PLATFORM MATCHES "SDL1" AND BACKEND_RENDERER MATCHES "Software")
 	target_sources(CSE2 PRIVATE "src/Backends/Rendering/Window/Software/SDL1.cpp")
 elseif(BACKEND_PLATFORM MATCHES "GLFW3" AND BACKEND_RENDERER MATCHES "OpenGL3")
--- /dev/null
+++ b/src/Backends/Rendering/Window/OpenGL3/SDL1.cpp
@@ -1,0 +1,52 @@
+#include "../OpenGL.h"
+
+#include <stddef.h>
+#include <string>
+
+#include <glad/glad.h>
+#include "SDL.h"
+
+#include "../../../Misc.h"
+
+bool WindowBackend_OpenGL_CreateWindow(const char *window_title, int *screen_width, int *screen_height, bool fullscreen)
+{
+	if (SDL_SetVideoMode(*screen_width, *screen_height, 0, SDL_RESIZABLE | SDL_OPENGL | (fullscreen ? SDL_FULLSCREEN : 0)) != NULL)
+	{
+		SDL_WM_SetCaption(window_title, NULL);
+
+		if (gladLoadGLLoader((GLADloadproc)SDL_GL_GetProcAddress))
+		{
+			// Check if the platform supports OpenGL 3.2
+			if (GLAD_GL_VERSION_3_2)
+			{
+				Backend_PostWindowCreation();
+
+				return true;
+			}
+			else
+			{
+				Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Your system does not support OpenGL 3.2");
+			}
+		}
+		else
+		{
+			Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", "Couldn't load OpenGL functions");
+		}
+	}
+	else
+	{
+		std::string error_message = std::string("Could not create window: ") + SDL_GetError();
+		Backend_ShowMessageBox("Fatal error (OpenGL rendering backend)", error_message.c_str());
+	}
+
+	return false;
+}
+
+void WindowBackend_OpenGL_DestroyWindow(void)
+{
+}
+
+void WindowBackend_OpenGL_Display(void)
+{
+	SDL_GL_SwapBuffers();
+}