29 #include "../../ports/system.h"
30 #include "../client.h"
37 #include "../../ports/linux/ufoicon.xbm"
41 #if SDL_VERSION_ATLEAST(2,0,0)
42 SDL_SetColorKey(icon, SDL_TRUE, 0);
44 SDL_SetColorKey(icon, SDL_SRCCOLORKEY, 0);
47 color.r = color.g = color.b = 255;
48 SDL_SetColors(icon, &color, 0, 1);
50 color.r = color.b = 0;
52 SDL_SetColors(icon, &color, 1, 1);
55 Uint8 *ptr = (Uint8 *)icon->pixels;
56 for (
unsigned int i = 0;
i <
sizeof(ufoicon_bits);
i++) {
57 for (
unsigned int mask = 1; mask != 0x100; mask <<= 1) {
58 *ptr = (ufoicon_bits[
i] & mask) ? 1 : 0;
63 #if SDL_VERSION_ATLEAST(2,0,0)
64 SDL_SetWindowIcon(
cls.window, icon);
66 SDL_WM_SetIcon(icon,
nullptr);
68 SDL_FreeSurface(icon);
77 Com_Printf(
"\n------- video initialization -------\n");
87 Sys_Setenv(
"SDL_VIDEO_ALLOW_SCREENSAVER",
"0");
89 if (SDL_WasInit(SDL_INIT_VIDEO) == 0) {
90 if (SDL_Init(SDL_INIT_VIDEO) < 0)
95 Com_Printf(
"I: SDL version: %i.%i.%i\n", version.major, version.minor, version.patch);
100 #if SDL_VERSION_ATLEAST(2,0,0)
102 const int modes = SDL_GetNumDisplayModes(screen);
105 for (
int i = 0;
i < modes;
i++) {
106 SDL_DisplayMode displayMode;
107 SDL_GetDisplayMode(screen,
i, &displayMode);
108 r_sdl_config.
modes[
i][0] = displayMode.w;
109 r_sdl_config.
modes[
i][1] = displayMode.h;
113 const int displays = SDL_GetNumVideoDisplays();
114 Com_Printf(
"I: found %i display(s)\n", displays);
116 SDL_DisplayMode displayMode;
117 if (SDL_GetDesktopDisplayMode(0, &displayMode) != -1) {
118 const char*
name = SDL_GetPixelFormatName(displayMode.format);
119 Com_Printf(
"I: current desktop mode: %dx%d@%dHz (%s)\n",
120 displayMode.w, displayMode.h, displayMode.refresh_rate, name);
121 Com_Printf(
"I: video driver: %s\n", SDL_GetCurrentVideoDriver());
125 Com_Printf(
"E: failed to get the desktop mode\n");
128 const int videoDrivers = SDL_GetNumVideoDrivers();
129 for (
int i = 0;
i < videoDrivers; ++
i) {
130 Com_Printf(
"I: available driver: %s\n", SDL_GetVideoDriver(
i));
132 Com_Printf(
"I: driver: %s\n", SDL_GetCurrentVideoDriver());
134 SDL_SetModState(KMOD_NONE);
137 const SDL_VideoInfo* info = SDL_GetVideoInfo();
138 if (info !=
nullptr) {
139 SDL_VideoInfo videoInfo;
140 SDL_PixelFormat pixelFormat;
142 Com_Printf(
"I: desktop depth: %ibpp\n", info->vfmt->BitsPerPixel);
145 memcpy(&pixelFormat, info->vfmt,
sizeof(pixelFormat));
146 memcpy(&videoInfo, info,
sizeof(videoInfo));
147 videoInfo.vfmt = &pixelFormat;
148 modes = SDL_ListModes(videoInfo.vfmt, SDL_OPENGL | SDL_FULLSCREEN);
150 if (modes == (SDL_Rect**)-1) {
151 Com_Printf(
"I: Available resolutions: any resolution is supported\n");
152 r_sdl_config.
modes =
nullptr;
158 r_sdl_config.
modes[
i][0] = modes[
i]->w;
159 r_sdl_config.
modes[
i][1] = modes[
i]->h;
163 Com_Printf(
"I: Could not get list of available resolutions\n");
166 char videoDriverName[
MAX_VAR] =
"";
167 SDL_VideoDriverName(videoDriverName,
sizeof(videoDriverName));
168 Com_Printf(
"I: video driver: %s\n", videoDriverName);
172 Q_strcat(buf,
sizeof(buf),
"I: Available resolutions:");
182 #if !SDL_VERSION_ATLEAST(2,0,0)
187 SDL_EnableUNICODE(SDL_ENABLE);
188 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
193 if (!SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &attrValue))
194 Com_Printf(
"I: got %d bits of stencil\n", attrValue);
195 if (!SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &attrValue))
196 Com_Printf(
"I: got %d bits of depth buffer\n", attrValue);
197 if (!SDL_GL_GetAttribute(SDL_GL_DOUBLEBUFFER, &attrValue))
199 if (!SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &attrValue))
200 Com_Printf(
"I: got %d bits for red\n", attrValue);
201 if (!SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &attrValue))
202 Com_Printf(
"I: got %d bits for green\n", attrValue);
203 if (!SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &attrValue))
204 Com_Printf(
"I: got %d bits for blue\n", attrValue);
205 if (!SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &attrValue))
206 Com_Printf(
"I: got %d bits for alpha\n", attrValue);
207 if (!SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &attrValue))
208 Com_Printf(
"I: got multisample %s\n", attrValue != 0 ?
"enabled" :
"disabled");
209 if (!SDL_GL_GetAttribute(SDL_GL_MULTISAMPLEBUFFERS, &attrValue))
210 Com_Printf(
"I: got %d multisample buffers\n", attrValue);
220 SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
221 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
222 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
226 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1);
227 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, context->
multisample);
229 Com_Printf(
"I: disable multisample buffers\n");
230 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 0);
231 SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, 0);
234 #if SDL_VERSION_ATLEAST(2,0,0)
235 #ifdef GL_VERSION_ES_CM_1_0
237 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
238 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 1);
241 const int i = std::min(1, std::max(-1, context->
swapinterval));
243 SDL_GL_SetSwapInterval(i);
244 uint32_t flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
247 flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
251 const char* error = SDL_GetError();
252 Com_Printf(
"E: SDL_CreateWindow failed: %s\n", error);
257 cls.context = SDL_GL_CreateContext(
cls.window);
260 const int i = std::min(2, std::max(0, context->
swapinterval));
262 SDL_GL_SetAttribute(SDL_GL_SWAP_CONTROL, i);
263 uint32_t flags = SDL_OPENGL;
265 flags |= SDL_FULLSCREEN;
268 SDL_Surface* screen = SDL_SetVideoMode(context->
width, context->
height, 0, flags);
270 const char* error = SDL_GetError();
271 Com_Printf(
"SDL SetVideoMode failed: %s\n", error);
277 SDL_ShowCursor(SDL_DISABLE);
284 #if SDL_VERSION_ATLEAST(2,0,0)
285 SDL_DestroyWindow(
cls.window);
286 SDL_GL_DeleteContext(
cls.context);
290 SDL_ShowCursor(SDL_ENABLE);
292 if (SDL_WasInit(SDL_INIT_EVERYTHING) == SDL_INIT_VIDEO)
295 SDL_QuitSubSystem(SDL_INIT_VIDEO);
#define Mem_AllocTypeN(type, n)
int Sys_Setenv(const char *name, const char *value)
set/unset environment variables (empty value removes it)
local graphics definitions
void Com_Printf(const char *const fmt,...)
Contains the game screen context, everything that is needed to create the graphic context...
void Com_Error(int code, const char *fmt,...)
r_sdl_config_t r_sdl_config
static void R_SetSDLIcon(void)
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
bool R_InitGraphics(const viddefContext_t *context)
Init the SDL window.