Turn initial mode setting and WM setup into video_init
authorparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 16 Feb 2009 16:49:18 +0000 (16:49 +0000)
committerparasti <parasti@78b8d119-cf0a-0410-b17c-f493084dd1d7>
Mon, 16 Feb 2009 16:49:18 +0000 (16:49 +0000)
git-svn-id: https://s.snth.net/svn/neverball/trunk@2768 78b8d119-cf0a-0410-b17c-f493084dd1d7

ball/main.c
putt/main.c
share/video.c
share/video.h

index feb3be5..3224153 100644 (file)
@@ -30,7 +30,6 @@
 #include "set.h"
 #include "text.h"
 #include "tilt.h"
-#include "syswm.h"
 
 #include "st_conf.h"
 #include "st_title.h"
@@ -398,32 +397,10 @@ int main(int argc, char *argv[])
     audio_init();
     tilt_init();
 
-    /* Require 16-bit double buffer with 16-bit depth buffer. */
-
-    SDL_GL_SetAttribute(SDL_GL_RED_SIZE,     5);
-    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,   5);
-    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,    5);
-    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,  16);
-    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
-    /* This has to happen before mode setting... */
-
-    set_SDL_icon("icon/neverball.png");
-
     /* Initialize the video. */
 
-    if (!video_mode(config_get_d(CONFIG_FULLSCREEN),
-                    config_get_d(CONFIG_WIDTH), config_get_d(CONFIG_HEIGHT)))
-    {
-        fprintf(stderr, "%s\n", SDL_GetError());
+    if (!video_init(TITLE, "icon/neverball.png"))
         return 1;
-    }
-
-    /* ...and this has to happen after it. */
-
-    set_EWMH_icon("icon/neverball.png");
-
-    SDL_WM_SetCaption(TITLE, TITLE);
 
     init_state(&st_null);
 
index 0e25cdd..a0f53ce 100644 (file)
@@ -32,7 +32,6 @@
 #include "game.h"
 #include "gui.h"
 #include "text.h"
-#include "syswm.h"
 
 #include "st_conf.h"
 #include "st_all.h"
@@ -227,32 +226,12 @@ int main(int argc, char *argv[])
 
                 audio_init();
 
-                /* Require 16-bit double buffer with 16-bit depth buffer. */
-
-                SDL_GL_SetAttribute(SDL_GL_RED_SIZE,     5);
-                SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,   5);
-                SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,    5);
-                SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,  16);
-                SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
-
-                /* This has to happen before mode setting... */
-
-                set_SDL_icon("icon/neverputt.png");
-
                 /* Initialize the video. */
 
-                if (video_mode(config_get_d(CONFIG_FULLSCREEN),
-                               config_get_d(CONFIG_WIDTH),
-                               config_get_d(CONFIG_HEIGHT)))
+                if (video_init(TITLE, "icon/neverputt.png"))
                 {
                     int t1, t0 = SDL_GetTicks();
 
-                    /* ... and this has to happen after it. */
-
-                    set_EWMH_icon("icon/neverputt.png");
-
-                    SDL_WM_SetCaption(TITLE, TITLE);
-
                     /* Run the main game loop. */
 
                     init_state(&st_null);
@@ -271,7 +250,6 @@ int main(int argc, char *argv[])
                                 SDL_Delay(1);
                         }
                 }
-                else fprintf(stderr, "%s: %s\n", argv[0], SDL_GetError());
 
                 /* Restore Neverball's camera setting. */
 
index 316fb70..e0bf998 100644 (file)
 #include "vec3.h"
 #include "glext.h"
 #include "config.h"
+#include "syswm.h"
+
+/*---------------------------------------------------------------------------*/
+
+int video_init(const char *title, const char *icon)
+{
+    /* Require 16-bit double buffer with 16-bit depth buffer. */
+
+    SDL_GL_SetAttribute(SDL_GL_RED_SIZE,     5);
+    SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE,   5);
+    SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE,    5);
+    SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,  16);
+    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+
+    /* This has to happen before mode setting... */
+
+    set_SDL_icon(icon);
+
+    /* Initialize the video. */
+
+    if (!video_mode(config_get_d(CONFIG_FULLSCREEN),
+                    config_get_d(CONFIG_WIDTH), config_get_d(CONFIG_HEIGHT)))
+    {
+        fprintf(stderr, "%s\n", SDL_GetError());
+        return 0;
+    }
+
+    /* ...and this has to happen after it. */
+
+    set_EWMH_icon(icon);
+
+    SDL_WM_SetCaption(title, title);
+
+    return 1;
+}
 
 /*---------------------------------------------------------------------------*/
 
index 795019b..a225a5c 100644 (file)
 
 /*---------------------------------------------------------------------------*/
 
+int video_init(const char *, const char *);
+
+/*---------------------------------------------------------------------------*/
+
 int  video_mode(int, int, int);
 
 int  video_perf(void);