1 #ifdef HAVE_CONFIG_H
2 # include "config.h"
3 #endif
4 
5 #ifdef HAVE_STRING_H
6 # include <string.h>
7 #endif
8 #ifdef HAVE_STRINGS_H
9 # include <strings.h>
10 #endif
11 
12 #include <stdlib.h>
13 #include <SDL.h>
14 
15 #include "QF/cvar.h"
16 #include "QF/input.h"
17 #include "QF/sys.h"
18 #include "QF/va.h"
19 #include "QF/vid.h"
20 
21 #include "context_sdl.h"
22 #include "vid_internal.h"
23 
24 cvar_t     *vid_bitdepth;
25 
26 extern SDL_Surface *screen;
27 
28 
29 void
VID_SDL_GammaCheck(void)30 VID_SDL_GammaCheck (void)
31 {
32 	Uint16 redtable[256], greentable[256], bluetable[256];
33 
34 	if (SDL_GetGammaRamp(redtable, greentable, bluetable) < 0)
35 		vid_gamma_avail = false;
36 	else
37 		vid_gamma_avail = true;
38 }
39 
40 void
VID_SetCaption(const char * text)41 VID_SetCaption (const char *text)
42 {
43 	if (text && *text) {
44 		char		*temp = strdup (text);
45 
46 		SDL_WM_SetCaption (va ("%s: %s", PACKAGE_STRING, temp), NULL);
47 		free (temp);
48 	} else {
49 		SDL_WM_SetCaption (va ("%s", PACKAGE_STRING), NULL);
50 	}
51 }
52 
53 qboolean
VID_SetGamma(double gamma)54 VID_SetGamma (double gamma)
55 {
56 	return SDL_SetGamma((float) gamma, (float) gamma, (float) gamma);
57 }
58 
59 void
VID_Shutdown(void)60 VID_Shutdown (void)
61 {
62 	SDL_Quit ();
63 }
64 
65 static void
VID_UpdateFullscreen(cvar_t * vid_fullscreen)66 VID_UpdateFullscreen (cvar_t *vid_fullscreen)
67 {
68 	if (!r_data || !viddef.initialized)
69 		return;
70 	if ((vid_fullscreen->int_val && !(screen->flags & SDL_FULLSCREEN))
71 		|| (!vid_fullscreen->int_val && screen->flags & SDL_FULLSCREEN))
72 		if (!SDL_WM_ToggleFullScreen (screen))
73 			Sys_Printf ("VID_UpdateFullscreen: error setting fullscreen\n");
74 	IN_UpdateGrab (in_grab);
75 }
76 
77 void
SDL_Init_Cvars(void)78 SDL_Init_Cvars (void)
79 {
80 	vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ARCHIVE,
81 							   VID_UpdateFullscreen,
82 							   "Toggles fullscreen mode");
83 	vid_system_gamma = Cvar_Get ("vid_system_gamma", "1", CVAR_ARCHIVE, NULL,
84 								 "Use system gamma control if available");
85 // FIXME: vid_colorbpp in common GL setup, make consistent with sdl32 scheme
86 	vid_bitdepth = Cvar_Get ("vid_bitdepth", "8", CVAR_ROM, NULL, "Sets "
87 							 "display bitdepth (supported modes: 8 16 32)");
88 }
89