UFO: Alien Invasion
Loading...
Searching...
No Matches
cl_video.cpp
Go to the documentation of this file.
1
5
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
42
47
51static const vidmode_t vid_modes[] =
52{
53 { 320, 240, 0 },
54 { 400, 300, 1 },
55 { 512, 384, 2 },
56 { 640, 480, 3 },
57 { 800, 600, 4 },
58 { 960, 720, 5 },
59 { 1024, 768, 6 },
60 { 1152, 864, 7 },
61 { 1280, 1024, 8 },
62 { 1600, 1200, 9 },
63 { 2048, 1536, 10 },
64 { 1024, 480, 11 }, /* Sony VAIO Pocketbook */
65 { 1152, 768, 12 }, /* Apple TiBook */
66 { 1280, 854, 13 }, /* Apple TiBook */
67 { 640, 400, 14 }, /* generic 16:10 widescreen*/
68 { 800, 500, 15 }, /* as found modern */
69 { 1024, 640, 16 }, /* notebooks */
70 { 1280, 800, 17 },
71 { 1680, 1050, 18 },
72 { 1920, 1200, 19 },
73 { 1400, 1050, 20 }, /* samsung x20 */
74 { 1440, 900, 21 },
75 { 1024, 600, 22 }, /* EEE PC */
76 { 800, 480, 23 }, /* OpenPandora */
77 { 1920, 1080, 24 }, /* 1080p */
78 { 1366, 768, 25 }
79};
80
85{
86 if (r_sdl_config.numModes > 0)
87 return r_sdl_config.numModes;
88 return lengthof(vid_modes);
89}
90
91bool VID_GetModeInfo (int modeIndex, vidmode_t* modeInfo)
92{
93 if (modeIndex < 0) {
94 modeInfo->width = vid_width->integer;
95 modeInfo->height = vid_height->integer;
96 if (modeInfo->width <= 0 || modeInfo->height <= 0) {
97 Com_Printf("I: using the desktop resolution because vid_mode, vid_height and vid_width are set to -1 (%ix%i)\n",
98 r_sdl_config.desktopWidth, r_sdl_config.desktopHeight);
99 modeInfo->width = r_sdl_config.desktopWidth;
100 modeInfo->height = r_sdl_config.desktopHeight;
101 }
102 } else if (modeIndex < VID_GetModeNums()) {
103 int width, height;
104 if (r_sdl_config.numModes > 0) {
105 width = r_sdl_config.modes[modeIndex][0];
106 height = r_sdl_config.modes[modeIndex][1];
107 } else {
108 width = vid_modes[modeIndex].width;
109 height = vid_modes[modeIndex].height;
110 }
111 modeInfo->width = width;
112 modeInfo->height = height;
113 } else {
114 return false;
115 }
116
117 return true;
118}
119
123static void VID_Restart_f (void)
124{
125 refdef.ready = false;
126
127 Com_Printf("renderer restart\n");
128
129 R_Shutdown();
130 R_Init();
131 UI_Reinit();
134
136 /*CL_ViewLoadMedia();*/
138}
139
140static bool CL_CvarCheckVidGamma (cvar_t* cvar)
141{
142 return Cvar_AssertValue(cvar, 0.1, 3.0, false);
143}
144
145static bool CL_CvarCheckVidMode (cvar_t* cvar)
146{
147 return Cvar_AssertValue(cvar, -1, VID_GetModeNums(), true);
148}
149
150void VID_Minimize (void)
151{
152 SDL_MinimizeWindow(cls.window);
153}
154
158void VID_Init (void)
159{
160 vid_stretch = Cvar_Get("vid_stretch", "0", CVAR_ARCHIVE | CVAR_R_CONTEXT, "Backward compatibility to stretch the screen with a 4:3 ratio");
161 vid_fullscreen = Cvar_Get("vid_fullscreen", "1", CVAR_ARCHIVE | CVAR_R_CONTEXT, "Run the game in fullscreen mode");
162 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");
164 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");
165 vid_gamma = Cvar_Get("vid_gamma", "1", CVAR_ARCHIVE, "Controls the gamma settings");
166 vid_ignoregamma = Cvar_Get("vid_ignoregamma", "0", CVAR_ARCHIVE, "Don't control the gamma settings if set to 1");
168 vid_left = Cvar_Get("vid_left", va("%d", VID_POS_UNSET), CVAR_ARCHIVE, "Screen position for windowed mode, left coordinate");
169 vid_top = Cvar_Get("vid_top", va("%d", VID_POS_UNSET), CVAR_ARCHIVE, "Screen position for windowed mode, top coordinate");
170 vid_width = Cvar_Get("vid_width", "-1", CVAR_ARCHIVE, "Custom video width - set vid_mode to -1 to use this");
171 vid_height = Cvar_Get("vid_height", "-1", CVAR_ARCHIVE, "Custom video height - set vid_mode to -1 to use this");
172
173 Cmd_AddCommand("vid_restart", VID_Restart_f, "Restart the renderer - or change the resolution");
174 Cmd_AddCommand("vid_minimize", VID_Minimize, "Minimize the game window");
175
176 /* memory pools */
177 vid_genericPool = Mem_CreatePool("Vid: Generic");
178 vid_imagePool = Mem_CreatePool("Vid: Image system");
179 vid_lightPool = Mem_CreatePool("Vid: Light system");
180 vid_modelPool = Mem_CreatePool("Vid: Model system");
181
182 /* Start the graphics mode */
183 R_Init();
184}
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:46
static bool CL_CvarCheckVidGamma(cvar_t *cvar)
Definition cl_video.cpp:140
void VID_Minimize(void)
Definition cl_video.cpp:150
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:51
static cvar_t * vid_left
Definition cl_video.cpp:43
void VID_Init(void)
Definition cl_video.cpp:158
cvar_t * vid_stretch
Definition cl_video.cpp:36
static cvar_t * vid_width
Definition cl_video.cpp:45
static bool CL_CvarCheckVidMode(cvar_t *cvar)
Definition cl_video.cpp:145
static void VID_Restart_f(void)
Perform a renderer restart.
Definition cl_video.cpp:123
viddef_t viddef
Definition cl_video.cpp:34
bool VID_GetModeInfo(int modeIndex, vidmode_t *modeInfo)
Definition cl_video.cpp:91
cvar_t * vid_mode
Definition cl_video.cpp:38
int VID_GetModeNums(void)
Returns the amount of available video modes.
Definition cl_video.cpp:84
static cvar_t * vid_top
Definition cl_video.cpp:44
cvar_t * vid_ignoregamma
Definition cl_video.cpp:41
Video driver defs.
#define VID_POS_UNSET
Definition cl_video.h:37
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:428
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:1259
void R_Shutdown(void)
Definition r_main.cpp:1315
r_sdl_config_t r_sdl_config
Definition r_sdl.cpp:32
#define lengthof(x)
Definition shared.h:105
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
Definition shared.cpp:410
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
Definition cvar.h:71
Contains the game screen size and drawing scale.
Definition cl_video.h:69
int height
Definition cl_video.h:86
int width
Definition cl_video.h:86
void UI_Reinit(void)
Definition ui_main.cpp:191