share/gui: don't use less of widget width for truncation than available
[neverball] / share / video.c
index 19408a0..0e970d7 100644 (file)
 #include "vec3.h"
 #include "glext.h"
 #include "config.h"
+#include "syswm.h"
+
+/*---------------------------------------------------------------------------*/
+
+int video_init(const char *title, const char *icon)
+{
+    SDL_QuitSubSystem(SDL_INIT_VIDEO);
+
+    if (SDL_InitSubSystem(SDL_INIT_VIDEO) == -1)
+    {
+        fprintf(stderr, "%s\n", SDL_GetError());
+        return 0;
+    }
+
+    /* 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;
+}
 
 /*---------------------------------------------------------------------------*/
 
@@ -38,7 +74,7 @@ int check_extension(const char *needle)
     return 0;
 }
 
-int config_mode(int f, int w, int h)
+int video_mode(int f, int w, int h)
 {
     int stereo  = config_get_d(CONFIG_STEREO)      ? 1 : 0;
     int stencil = config_get_d(CONFIG_REFLECTION)  ? 1 : 0;
@@ -52,6 +88,14 @@ int config_mode(int f, int w, int h)
     SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, samples);
     SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL,       vsync);
 
+    /* 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);
+
     /* Try to set the currently specified mode. */
 
     if (SDL_SetVideoMode(w, h, 0, SDL_OPENGL | (f ? SDL_FULLSCREEN : 0)))
@@ -77,14 +121,6 @@ int config_mode(int f, int w, int h)
         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
         glDepthFunc(GL_LEQUAL);
 
-        /*
-         * Mac OS X might still need this, because apparently SDL doesn't do
-         * SDL_GL_SWAP_CONTROL on OS X.  TODO: investigate.
-         */
-#if 0
-        if (vsync) sync_init();
-#endif
-
         /* If GL supports multisample, and SDL got a multisample buffer... */
 
 #ifdef GL_ARB_multisample
@@ -96,6 +132,8 @@ int config_mode(int f, int w, int h)
         }
 #endif
 
+        glReadBuffer(GL_FRONT);
+
         return 1;
     }
 
@@ -104,7 +142,7 @@ int config_mode(int f, int w, int h)
     else if (stereo)
     {
         config_set_d(CONFIG_STEREO, 0);
-        return config_mode(f, w, h);
+        return video_mode(f, w, h);
     }
 
     /* If the mode failed, try decreasing the level of multisampling. */
@@ -112,7 +150,7 @@ int config_mode(int f, int w, int h)
     else if (buffers)
     {
         config_set_d(CONFIG_MULTISAMPLE, samples / 2);
-        return config_mode(f, w, h);
+        return video_mode(f, w, h);
     }
 
     /* If that mode failed, try it without reflections. */
@@ -120,7 +158,7 @@ int config_mode(int f, int w, int h)
     else if (stencil)
     {
         config_set_d(CONFIG_REFLECTION, 0);
-        return config_mode(f, w, h);
+        return video_mode(f, w, h);
     }
 
     /* If THAT mode failed, punt. */
@@ -136,12 +174,12 @@ static int   last   = 0;
 static int   ticks  = 0;
 static int   frames = 0;
 
-int  config_perf(void)
+int  video_perf(void)
 {
     return fps;
 }
 
-void config_swap(void)
+void video_swap(void)
 {
     int dt;
 
@@ -186,7 +224,7 @@ void config_swap(void)
 
 static int grabbed = 0;
 
-void config_set_grab(int w)
+void video_set_grab(int w)
 {
     if (w)
     {
@@ -204,21 +242,21 @@ void config_set_grab(int w)
     grabbed = 1;
 }
 
-void config_clr_grab(void)
+void video_clr_grab(void)
 {
     SDL_WM_GrabInput(SDL_GRAB_OFF);
     SDL_ShowCursor(SDL_ENABLE);
     grabbed = 0;
 }
 
-int  config_get_grab(void)
+int  video_get_grab(void)
 {
     return grabbed;
 }
 
 /*---------------------------------------------------------------------------*/
 
-void config_push_persp(float fov, float n, float f)
+void video_push_persp(float fov, float n, float f)
 {
     GLdouble m[4][4];
 
@@ -256,7 +294,7 @@ void config_push_persp(float fov, float n, float f)
     glMatrixMode(GL_MODELVIEW);
 }
 
-void config_push_ortho(void)
+void video_push_ortho(void)
 {
     GLdouble w = (GLdouble) config_get_d(CONFIG_WIDTH);
     GLdouble h = (GLdouble) config_get_d(CONFIG_HEIGHT);
@@ -270,7 +308,7 @@ void config_push_ortho(void)
     glMatrixMode(GL_MODELVIEW);
 }
 
-void config_pop_matrix(void)
+void video_pop_matrix(void)
 {
     glMatrixMode(GL_PROJECTION);
     {
@@ -279,7 +317,7 @@ void config_pop_matrix(void)
     glMatrixMode(GL_MODELVIEW);
 }
 
-void config_clear(void)
+void video_clear(void)
 {
     if (config_get_d(CONFIG_REFLECTION))
         glClear(GL_COLOR_BUFFER_BIT |