All pastes #436732 Raw Edit

Miscellany

public text v1 · immutable
·published 2007-04-12 18:12 UTC
rendered paste body
/**
 * @brief Init the SDL window
 * @param fullscreen Start in fullscreen or not (bool value)
 */
static qboolean GLimp_InitGraphics (qboolean fullscreen)
{
	int flags;
	int stencil_bits;
#ifndef __APPLE__
	int width = 0;
	int height = 0;
#endif

	SDL_SysWMinfo info;
	SDL_VERSION(&info.version);
	Com_Printf("SDL version: %i.%i.%i\n", info.version.major, info.version.minor, info.version.patch);
	have_stencil = qfalse;

#ifndef __APPLE__
	/* turn off DGA mouse support: leaving it makes cursor _slow_ in fullscreen under X11 at least */
	setenv("SDL_VIDEO_X11_DGAMOUSE", "0", 1);

	if (SDL_GetWMInfo(&info) > 0 ) {
		if (info.subsystem == SDL_SYSWM_X11) {
			info.info.x11.lock_func();
			width = DisplayWidth(info.info.x11.display, DefaultScreen(info.info.x11.display));
			height = DisplayHeight(info.info.x11.display, DefaultScreen(info.info.x11.display));
			info.info.x11.unlock_func();
			Com_Printf("Desktop resolution: %i:%i\n", width, height);
		}
	}
#endif

	/* Just toggle fullscreen if that's all that has been changed */
	if (surface && (surface->w == vid.width) && (surface->h == vid.height)) {
		qboolean isfullscreen = (surface->flags & SDL_FULLSCREEN) ? qtrue : qfalse;
		if (fullscreen != isfullscreen)
			SDL_WM_ToggleFullScreen(surface);

		isfullscreen = (surface->flags & SDL_FULLSCREEN) ? qtrue : qfalse;
		if (fullscreen == isfullscreen)
			return qtrue;
	}

	srandom(getpid());

	/* free resources in use */
	if (surface)
		SDL_FreeSurface(surface);

	/* let the sound and input subsystems know about the new window */
	ri.Vid_NewWindow (vid.width, vid.height);

	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);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1);

	flags = SDL_OPENGL;
	if (fullscreen)
		flags |= SDL_FULLSCREEN;

	SetSDLIcon(); /* currently uses ufoicon.xbm data */

	if ((surface = SDL_SetVideoMode(vid.width, vid.height, 0, flags)) == NULL) {
		Sys_Error("(SDLGL) SDL SetVideoMode failed: %s\n", SDL_GetError());
		return qfalse;
	}

	SDL_WM_SetCaption(GAME_TITLE, GAME_TITLE_LONG);

	SDL_ShowCursor(SDL_DISABLE);

	if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_bits)) {
		ri.Con_Printf(PRINT_ALL, "I: got %d bits of stencil\n", stencil_bits);
		if (stencil_bits >= 1) {
			have_stencil = qtrue;
		}
	}

	SDL_active = qtrue;

	return qtrue;
}