UFO: Alien Invasion
cl_video.cpp
Go to the documentation of this file.
1
6/*
7Copyright (C) 1997-2001 Id Software, Inc.
8
9This program is free software; you can redistribute it and/or
10modify it under the terms of the GNU General Public License
11as published by the Free Software Foundation; either version 2
12of the License, or (at your option) any later version.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
17
18See the GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
23
24*/
25
26#include "cl_video.h"
27#include "client.h"
28#include "battlescape/cl_view.h"
29#include "renderer/r_main.h"
30#include "renderer/r_sdl.h"
31#include "ui/ui_main.h"
32#include "cgame/cl_game.h"
33
34viddef_t viddef; /* global video state; used by other modules */
35
44
48static const vidmode_t vid_modes[] =
49{
50 { 320, 240, 0 },
51 { 400, 300, 1 },
52 { 512, 384, 2 },
53 { 640, 480, 3 },
54 { 800, 600, 4 },
55 { 960, 720, 5 },
56 { 1024, 768, 6 },
57 { 1152, 864, 7 },
58 { 1280, 1024, 8 },
59 { 1600, 1200, 9 },
60 { 2048, 1536, 10 },
61 { 1024, 480, 11 }, /* Sony VAIO Pocketbook */
62 { 1152, 768, 12 }, /* Apple TiBook */
63 { 1280, 854, 13 }, /* Apple TiBook */
64 { 640, 400, 14 }, /* generic 16:10 widescreen*/
65 { 800, 500, 15 }, /* as found modern */
66 { 1024, 640, 16 }, /* notebooks */
67 { 1280, 800, 17 },
68 { 1680, 1050, 18 },
69 { 1920, 1200, 19 },
70 { 1400, 1050, 20 }, /* samsung x20 */
71 { 1440, 900, 21 },
72 { 1024, 600, 22 }, /* EEE PC */
73 { 800, 480, 23 }, /* OpenPandora */
74 { 1920, 1080, 24 }, /* 1080p */
75 { 1366, 768, 25 }
76};
77
82{
83 if (r_sdl_config.numModes > 0)
85 return lengthof(vid_modes);
86}
87
88bool VID_GetModeInfo (int modeIndex, vidmode_t* modeInfo)
89{
90 if (modeIndex < 0) {
91 modeInfo->width = vid_width->integer;
92 modeInfo->height = vid_height->integer;
93 if (modeInfo->width <= 0 || modeInfo->height <= 0) {
94 Com_Printf("I: using the desktop resolution because vid_mode, vid_height and vid_width are set to -1 (%ix%i)\n",
98 }
99 } else if (modeIndex < VID_GetModeNums()) {
100 int width, height;
101 if (r_sdl_config.numModes > 0) {
102 width = r_sdl_config.modes[modeIndex][0];
103 height = r_sdl_config.modes[modeIndex][1];
104 } else {
105 width = vid_modes[modeIndex].width;
106 height = vid_modes[modeIndex].height;
107 }
108 modeInfo->width = width;
109 modeInfo->height = height;
110 } else {
111 return false;
112 }
113
114 return true;
115}
116
120static void VID_Restart_f (void)
121{
122 refdef.ready = false;
123
124 Com_Printf("renderer restart\n");
125
126 R_Shutdown();
127 R_Init();
128 UI_Reinit();
131
133 /*CL_ViewLoadMedia();*/
135}
136
137static bool CL_CvarCheckVidGamma (cvar_t* cvar)
138{
139 return Cvar_AssertValue(cvar, 0.1, 3.0, false);
140}
141
142static bool CL_CvarCheckVidMode (cvar_t* cvar)
143{
144 return Cvar_AssertValue(cvar, -1, VID_GetModeNums(), true);
145}
146
147void VID_Minimize (void)
148{
149#if SDL_VERSION_ATLEAST(2,0,0)
150 SDL_MinimizeWindow(cls.window);
151#else
152 SDL_WM_IconifyWindow();
153#endif
154}
155
159void VID_Init (void)
160{
161 vid_stretch = Cvar_Get("vid_stretch", "0", CVAR_ARCHIVE | CVAR_R_CONTEXT, "Backward compatibility to stretch the screen with a 4:3 ratio");
162 vid_fullscreen = Cvar_Get("vid_fullscreen", "1", CVAR_ARCHIVE | CVAR_R_CONTEXT, "Run the game in fullscreen mode");
163 vid_mode = Cvar_Get("vid_mode", "-1", CVAR_ARCHIVE | CVAR_R_CONTEXT, "The video mode - set to -1 and use vid_width and vid_height to use a custom resolution");
165 vid_grabmouse = Cvar_Get("vid_grabmouse", "0", CVAR_ARCHIVE, "Grab the mouse in the game window - open the console to switch back to your desktop via Alt+Tab");
166 vid_gamma = Cvar_Get("vid_gamma", "1", CVAR_ARCHIVE, "Controls the gamma settings");
167 vid_ignoregamma = Cvar_Get("vid_ignoregamma", "0", CVAR_ARCHIVE, "Don't control the gamma settings if set to 1");
169 vid_height = Cvar_Get("vid_height", "-1", CVAR_ARCHIVE, "Custom video height - set vid_mode to -1 to use this");
170 vid_width = Cvar_Get("vid_width", "-1", CVAR_ARCHIVE, "Custom video width - set vid_mode to -1 to use this");
171
172 Cmd_AddCommand("vid_restart", VID_Restart_f, "Restart the renderer - or change the resolution");
173 Cmd_AddCommand("vid_minimize", VID_Minimize, "Minimize the game window");
174
175 /* memory pools */
176 vid_genericPool = Mem_CreatePool("Vid: Generic");
177 vid_imagePool = Mem_CreatePool("Vid: Image system");
178 vid_lightPool = Mem_CreatePool("Vid: Light system");
179 vid_modelPool = Mem_CreatePool("Vid: Model system");
180
181 /* Start the graphics mode */
182 R_Init();
183}
void GAME_ReloadMode(void)
Definition: cl_game.cpp:290
Shared game type headers.
memPool_t * vid_genericPool
Definition: cl_main.cpp:87
memPool_t * vid_imagePool
Definition: cl_main.cpp:88
client_static_t cls
Definition: cl_main.cpp:83
memPool_t * vid_modelPool
Definition: cl_main.cpp:90
memPool_t * vid_lightPool
Definition: cl_main.cpp:89
rendererData_t refdef
Definition: r_main.cpp:45
cvar_t * vid_grabmouse
Definition: cl_video.cpp:39
static cvar_t * vid_height
Definition: cl_video.cpp:42
static bool CL_CvarCheckVidGamma(cvar_t *cvar)
Definition: cl_video.cpp:137
void VID_Minimize(void)
Definition: cl_video.cpp:147
cvar_t * vid_gamma
Definition: cl_video.cpp:40
cvar_t * vid_fullscreen
Definition: cl_video.cpp:37
static const vidmode_t vid_modes[]
All possible video modes.
Definition: cl_video.cpp:48
void VID_Init(void)
Definition: cl_video.cpp:159
cvar_t * vid_stretch
Definition: cl_video.cpp:36
static cvar_t * vid_width
Definition: cl_video.cpp:43
static bool CL_CvarCheckVidMode(cvar_t *cvar)
Definition: cl_video.cpp:142
static void VID_Restart_f(void)
Perform a renderer restart.
Definition: cl_video.cpp:120
viddef_t viddef
Definition: cl_video.cpp:34
bool VID_GetModeInfo(int modeIndex, vidmode_t *modeInfo)
Definition: cl_video.cpp:88
cvar_t * vid_mode
Definition: cl_video.cpp:38
int VID_GetModeNums(void)
Returns the amount of available video modes.
Definition: cl_video.cpp:81
cvar_t * vid_ignoregamma
Definition: cl_video.cpp:41
Video driver defs.
void CL_ViewPrecacheModels(void)
Precaches all models at game startup - for faster access.
Definition: cl_view.cpp:152
Primary header for client.
void Cmd_AddCommand(const char *cmdName, xcommand_t function, const char *desc)
Add a new command to the script interface.
Definition: cmd.cpp:744
void Com_Printf(const char *const fmt,...)
Definition: common.cpp:386
bool Cvar_SetCheckFunction(const char *varName, bool(*check)(cvar_t *cvar))
Set a checker function for cvar values.
Definition: cvar.cpp:139
bool Cvar_AssertValue(cvar_t *cvar, float minVal, float maxVal, bool shouldBeIntegral)
Checks cvar values.
Definition: cvar.cpp:161
cvar_t * Cvar_Get(const char *var_name, const char *var_value, int flags, const char *desc)
Init or return a cvar.
Definition: cvar.cpp:342
#define CVAR_ARCHIVE
Definition: cvar.h:40
#define CVAR_R_CONTEXT
Definition: cvar.h:48
#define Mem_CreatePool(name)
Definition: mem.h:32
bool R_Init(void)
Definition: r_main.cpp:1263
void R_Shutdown(void)
Definition: r_main.cpp:1319
r_sdl_config_t r_sdl_config
Definition: r_sdl.cpp:32
#define lengthof(x)
Definition: shared.h:105
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition: cvar.h:71
int integer
Definition: cvar.h:81
int numModes
Definition: r_sdl.h:31
rect_t * modes
Definition: r_sdl.h:30
int desktopHeight
Definition: r_sdl.h:34
int desktopWidth
Definition: r_sdl.h:33
Contains the game screen size and drawing scale.
Definition: cl_video.h:66
int height
Definition: cl_video.h:83
int width
Definition: cl_video.h:83
void UI_Reinit(void)
Definition: ui_main.cpp:191