diff dmrender.h @ 63:d6ffc59bb84d

Move more of the SDL and GL setup code to the renderer class.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 14 Dec 2019 20:13:32 +0200
parents baccf2044289
children 9ee0edff3940
line wrap: on
line diff
--- a/dmrender.h	Sat Dec 14 16:39:20 2019 +0200
+++ b/dmrender.h	Sat Dec 14 20:13:32 2019 +0200
@@ -16,10 +16,13 @@
 struct DMSimpleRenderer
 {
     bool useShaders;
+    int windowWidth, windowHeight;
+    SDL_Window *sdlWindow;
 
     DMSimpleRenderer()
     {
         useShaders = false;
+        sdlWindow = NULL;
     }
 
     virtual bool checkErrors(void)
@@ -27,27 +30,42 @@
         return true;
     }
 
-    virtual bool initRender1(void)
+    virtual bool initRenderer1(const char *title,
+        const int width, const int height,
+        const int sdlWindowHPos, const int sdlWindowVPos,
+        const int sdlFlags)
     {
-        return false;
+        windowWidth = width;
+        windowHeight = height;
+
+        if ((sdlWindow = SDL_CreateWindow(title,
+            sdlWindowHPos, sdlWindowVPos,
+            windowWidth, windowHeight,
+            sdlFlags)) == NULL)
+        {
+            dmError("Could not create SDL window: %s",
+                SDL_GetError());
+
+            return false;
+        }
+        else
+            return true;
     }
 
-    virtual bool initRender2(SDL_Window *window)
+    virtual bool initRenderer2(void)
     {
-        (void) window;
-        return false;
-    }
-
-    virtual bool initRender3(const int width, const int height)
-    {
-        (void) width;
-        (void) height;
-
         return false;
     }
 
     virtual void shutdownRenderer(void)
     {
+        if (sdlWindow != NULL)
+            SDL_DestroyWindow(sdlWindow);
+    }
+
+    virtual void swapWindow(void)
+    {
+        SDL_GL_SwapWindow(sdlWindow);
     }
 
     virtual void drawModel(const DMSimpleScene &scene, const DMModel &model, const float time)