summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2022-11-11 19:41:28 +0000
committerDan Goodliffe <dan@randomdan.homeip.net>2022-11-14 23:45:57 +0000
commit915c18b874c0fd4fab5da60e416ecf405512a8f7 (patch)
tree49e9be2b7388d94d36590fafe918fc2814763740
parentRestructure how shaders are worked with (diff)
downloadilt-915c18b874c0fd4fab5da60e416ecf405512a8f7.tar.bz2
ilt-915c18b874c0fd4fab5da60e416ecf405512a8f7.tar.xz
ilt-915c18b874c0fd4fab5da60e416ecf405512a8f7.zip
Extract SDL_Application helper into libilt
-rw-r--r--application/main.cpp31
-rw-r--r--ui/applicationBase.cpp24
-rw-r--r--ui/applicationBase.h12
3 files changed, 39 insertions, 28 deletions
diff --git a/application/main.cpp b/application/main.cpp
index a70fd35..224c4f7 100644
--- a/application/main.cpp
+++ b/application/main.cpp
@@ -1,4 +1,3 @@
-#include <SDL2/SDL.h>
#include <array>
#include <chrono>
#include <collection.hpp>
@@ -21,6 +20,7 @@
#include <glm/gtx/transform.hpp> // IWYU pragma: keep
#include <memory>
#include <special_members.hpp>
+#include <ui/applicationBase.h>
#include <ui/gameMainWindow.h>
#include <ui/window.h>
#include <vector>
@@ -28,33 +28,8 @@
static const int DISPLAY_WIDTH = 1280;
static const int DISPLAY_HEIGHT = 1024;
-class SDL_Application : public GameState {
+class MainApplication : public GameState, public ApplicationBase {
public:
- SDL_Application()
- {
- SDL_Init(SDL_INIT_EVERYTHING);
-
- SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
- SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
- }
-
- ~SDL_Application()
- {
- SDL_Quit();
- }
-
- NO_COPY(SDL_Application);
- NO_MOVE(SDL_Application);
-
using Windows = Collection<Window>;
int
run()
@@ -135,5 +110,5 @@ private:
int
main(int, char **)
{
- return std::make_shared<SDL_Application>()->run();
+ return std::make_shared<MainApplication>()->run();
}
diff --git a/ui/applicationBase.cpp b/ui/applicationBase.cpp
new file mode 100644
index 0000000..5c87359
--- /dev/null
+++ b/ui/applicationBase.cpp
@@ -0,0 +1,24 @@
+#include "applicationBase.h"
+#include <SDL2/SDL.h>
+
+ApplicationBase::ApplicationBase()
+{
+ SDL_Init(SDL_INIT_EVERYTHING);
+
+ SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);
+ SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 16);
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 4);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 5);
+}
+
+ApplicationBase::~ApplicationBase()
+{
+ SDL_Quit();
+}
diff --git a/ui/applicationBase.h b/ui/applicationBase.h
new file mode 100644
index 0000000..57995ca
--- /dev/null
+++ b/ui/applicationBase.h
@@ -0,0 +1,12 @@
+#pragma once
+
+#include <special_members.hpp>
+
+class ApplicationBase {
+public:
+ ApplicationBase();
+ virtual ~ApplicationBase();
+
+ NO_COPY(ApplicationBase);
+ NO_MOVE(ApplicationBase);
+};