diff dmglrender.cpp @ 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 71f6c5cc8eec
line wrap: on
line diff
--- a/dmglrender.cpp	Sat Dec 14 16:39:20 2019 +0200
+++ b/dmglrender.cpp	Sat Dec 14 20:13:32 2019 +0200
@@ -103,7 +103,10 @@
 }
 
 
-bool DMGLSimpleRenderer::initRender1(void)
+bool DMGLSimpleRenderer::initRenderer1(const char *title,
+        const int width, const int height,
+        const int sdlWindowHPos, const int sdlWindowVPos,
+        const int sdlFlags)
 {
     // Set GL attributes
     SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
@@ -119,14 +122,16 @@
     //SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, 32);
     SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
 
-    return true;
-}
-
+    // Attempt to create a window
+    if (!DMSimpleRenderer::initRenderer1(
+        title,
+        width, height,
+        sdlWindowHPos, sdlWindowVPos,
+        sdlFlags | SDL_WINDOW_OPENGL))
+        return false;
 
-bool DMGLSimpleRenderer::initRender2(SDL_Window *window)
-{
     // Create OpenGL context
-    if ((glContext = SDL_GL_CreateContext(window)) == NULL)
+    if ((sdlGLContext = SDL_GL_CreateContext(sdlWindow)) == NULL)
     {
         dmError("Unable to create SDL OpenGL context: %s\n",
             SDL_GetError());
@@ -160,7 +165,7 @@
 }
 
 
-bool DMGLSimpleRenderer::initRender3(const int width, const int height)
+bool DMGLSimpleRenderer::initRenderer2(void)
 {
     // Dump some information
     dmMsg("GL_VENDOR   : %s\n", glGetString(GL_VENDOR));
@@ -171,12 +176,12 @@
         return false;
 
     // Setup the window and view port
-    glViewport(0, 0, width, height);
+    glViewport(0, 0, windowWidth, windowHeight);
 
     glMatrixMode(GL_PROJECTION);
     glLoadIdentity();
 
-    gluPerspective(45.0f, GLfloat(width) / GLfloat(height), 0.1f, 1000.0f);
+    gluPerspective(45.0f, GLfloat(windowWidth) / GLfloat(windowHeight), 0.1f, 1000.0f);
 
     glMatrixMode(GL_MODELVIEW);
     glLoadIdentity();
@@ -231,8 +236,10 @@
 
 void DMGLSimpleRenderer::shutdownRenderer(void)
 {
-    if (glContext != NULL)
-        SDL_GL_DeleteContext(glContext);
+    if (sdlGLContext != NULL)
+        SDL_GL_DeleteContext(sdlGLContext);
+
+    DMSimpleRenderer::shutdownRenderer();
 }