#include "vec3.h"
#include "glext.h"
#include "config.h"
+#include "syswm.h"
+#include "sync.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;
+}
/*---------------------------------------------------------------------------*/
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;
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)))
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
}
#endif
+ glReadBuffer(GL_FRONT);
+
+ /* Attempt manual swap control if SDL's is broken. */
+
+ if (vsync && SDL_GL_GetAttribute(SDL_GL_SWAP_CONTROL, &vsync) == -1)
+ sync_init();
+
return 1;
}
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. */
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. */
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. */
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;
static int grabbed = 0;
-void config_set_grab(int w)
+void video_set_grab(int w)
{
if (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];
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);
glMatrixMode(GL_MODELVIEW);
}
-void config_pop_matrix(void)
+void video_pop_matrix(void)
{
glMatrixMode(GL_PROJECTION);
{
glMatrixMode(GL_MODELVIEW);
}
-void config_clear(void)
+void video_clear(void)
{
if (config_get_d(CONFIG_REFLECTION))
glClear(GL_COLOR_BUFFER_BIT |