DEADSOFTWARE

sdl2: fix fullscreen
[flatwaifu.git] / src / gl / render.c
index 91707ef5d32d2e7af2209a0a61d8c34d44672bb9..73ce92a4390892e76009478be58d04f916003c08 100644 (file)
@@ -1,5 +1,6 @@
 #include "glob.h"
 #include "render.h"
+#include "system.h"
 #include "files.h"
 #include "memory.h"
 #include "misc.h"
 #else
 #  include <GL/gl.h>
 #endif
-#include <stdlib.h> // malloc free abs
-#include <assert.h> // assert
-#include <SDL.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
 
 #define VGA_TRANSPARENT_COLOR 0
 #define DEFAULT_SKY_COLOR 0x97
@@ -80,7 +82,6 @@ int SCRW = 320; // public
 int SCRH = 200; // public
 static int gamma;
 static int fullscreen;
-static SDL_Surface *surf;
 static rgb playpal[256];
 static byte bright[256];
 static GLuint lastTexture;
@@ -1440,7 +1441,7 @@ void R_draw (void) {
       break;
   }
   GM_draw();
-  SDL_GL_SwapBuffers();
+  Y_swap_buffers();
 }
 
 void R_alloc (void) {
@@ -1669,21 +1670,34 @@ void R_alloc (void) {
   }
 }
 
-void R_init (void) {
-  Uint32 flags = SDL_OPENGL;
+void R_set_videomode (int w, int h, int fullscreen) {
+  assert(w > 0);
+  assert(h > 0);
+  int was = Y_videomode_setted();
+  int flags = SYSTEM_USE_OPENGL;
   if (fullscreen) {
-    flags = flags | SDL_FULLSCREEN;
-  }
-  if (SCRW <= 0 || SCRH <= 0) {
-    ERR_failinit("Invalid screen size %ix%i\n", SCRW, SCRH);
-  }
-  if (surf == NULL) {
-    R_init_playpal(); // only onece
+    flags |= SYSTEM_USE_FULLSCREEN;
   }
-  surf = SDL_SetVideoMode(SCRW, SCRH, 0, flags);
-  if (surf == NULL) {
-    ERR_failinit("Unable to set video mode: %s\n", SDL_GetError());
+  int res = Y_set_videomode(w, h, flags);
+  if (res == 0) {
+    if (was == 0) {
+      ERR_failinit("Unable to set video mode\n");
+    }
+  } else {
+    SCRW = w;
+    SCRH = h;
   }
+}
+
+void R_toggle_fullscreen (void) {
+  Y_set_fullscreen(!Y_get_fullscreen());
+  fullscreen = Y_get_fullscreen();
+}
+
+void R_init (void) {
+  logo("R_init: intialize opengl render\n");
+  R_init_playpal();
+  R_set_videomode(SCRW, SCRH, fullscreen);
   root = R_cache_new();
   assert(root);
   R_alloc();
@@ -1691,6 +1705,8 @@ void R_init (void) {
 
 void R_done (void) {
   R_cache_free(root, 1);
+  Y_unset_videomode();
+  root = NULL;
 }
 
 void R_setgamma (int g) {
@@ -1701,13 +1717,6 @@ int R_getgamma (void) {
   return gamma;
 }
 
-void R_toggle_fullscreen (void) {
-  fullscreen = !fullscreen;
-  if (surf) {
-    R_init(); // recreate window
-  }
-}
-
 void R_get_name (int n, char s[8]) {
   assert(n >= 0 && n < 256);
   if (walp[n].res == -1) {