static void VID_SDL_Init(void) { int flags; int r, g, b, a; if (glConfig.initialized == true) { return; } flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_SHOWN; #ifdef SDL_WINDOW_ALLOW_HIGHDPI flags |= SDL_WINDOW_ALLOW_HIGHDPI; #endif if (r_fullscreen.integer > 0) { if (vid_usedesktopres.integer == 1) { flags |= SDL_WINDOW_FULLSCREEN_DESKTOP; } } else { if (vid_win_borderless.integer > 0) { flags |= SDL_WINDOW_BORDERLESS; } } #ifdef __APPLE__ SDL_SetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, "0"); SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0"); #endif VID_SDL_InitSubSystem(); VID_SDL_GL_SetupAttributes(); VID_SetupModeList(); VID_SetupResolution(); if (r_fullscreen.integer == 0) { int displayNumber = VID_DisplayNumber(false); int xpos = vid_xpos.integer; int ypos = vid_ypos.integer; VID_AbsolutePositionFromRelative(&xpos, &ypos, &displayNumber); sdl_window = SDL_CreateWindow(WINDOW_CLASS_NAME, xpos, ypos, glConfig.vidWidth, glConfig.vidHeight, flags); } else { int windowWidth = glConfig.vidWidth; int windowHeight = glConfig.vidHeight; int windowX = SDL_WINDOWPOS_CENTERED; int windowY = SDL_WINDOWPOS_CENTERED; int displayNumber = VID_DisplayNumber(true); SDL_Rect bounds; if (SDL_GetDisplayBounds(displayNumber, &bounds) == 0) { windowX = bounds.x; windowY = bounds.y; windowWidth = bounds.w; windowHeight = bounds.h; } else { Com_Printf("Couldn't determine bounds of display #%d, defaulting to main display\n", displayNumber); } sdl_window = SDL_CreateWindow(WINDOW_CLASS_NAME, windowX, windowY, windowWidth, windowHeight, flags); } if (r_fullscreen.integer > 0 && vid_usedesktopres.integer != 1) { int index; index = VID_GetCurrentModeIndex(); /* FIXME: Make a pre-check if the values render a valid video mode before attempting to switch (when vid_usedesktopres != 1) !! */ if (index < 0) { Com_Printf("Couldn't find a matching video mode for the selected values, check video settings!\n"); } else { if (SDL_SetWindowDisplayMode(sdl_window, &modelist[index]) != 0) { Com_Printf("sdl error: %s\n", SDL_GetError()); } } if (SDL_SetWindowFullscreen(sdl_window, SDL_WINDOW_FULLSCREEN) < 0) { Com_Printf("Failed to change to fullscreen mode\n"); } } if (VID_SetWindowIcon(sdl_window) < 0) { Com_Printf("Failed to set window icon"); } SDL_SetWindowMinimumSize(sdl_window, 320, 240); sdl_context = SDL_GL_CreateContext(sdl_window); if (!sdl_context) { Com_Printf("Couldn't create OpenGL context: %s\n", SDL_GetError()); return; } v_gamma.modified = true; r_swapInterval.modified = true; SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &r); SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &g); SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &b); SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &a); glConfig.colorBits = r+g+b+a; SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &glConfig.depthBits); SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &glConfig.stencilBits); glConfig.vendor_string = glGetString(GL_VENDOR); glConfig.renderer_string = glGetString(GL_RENDERER); glConfig.version_string = glGetString(GL_VERSION); glConfig.extensions_string = glGetString(GL_EXTENSIONS); glConfig.initialized = true; }
static void VID_SDL_Init(void) { SDL_Surface *icon_surface; extern void InitSig(void); SDL_DisplayMode display_mode; int flags; if (glConfig.initialized == true) return; flags = SDL_WINDOW_FULLSCREEN | SDL_WINDOW_BORDERLESS | SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_SHOWN; #ifdef SDL_WINDOW_ALLOW_HIGHDPI flags |= SDL_WINDOW_ALLOW_HIGHDPI; #endif if (r_fullscreen.integer <= 0) { flags &= ~SDL_WINDOW_FULLSCREEN; if (vid_win_borderless.integer <= 0) flags &= ~SDL_WINDOW_BORDERLESS; } #if defined(__linux__) InitSig(); #endif VID_SDL_InitSubSystem(); VID_SDL_GL_SetupAttributes(); VID_SetupResolution(); sdl_window = SDL_CreateWindow(WINDOW_CLASS_NAME, vid_xpos.integer, vid_ypos.integer, glConfig.vidWidth, glConfig.vidHeight, flags); icon_surface = SDL_CreateRGBSurfaceFrom((void *)ezquake_icon.pixel_data, ezquake_icon.width, ezquake_icon.height, ezquake_icon.bytes_per_pixel * 8, ezquake_icon.width * ezquake_icon.bytes_per_pixel, 0x000000FF,0x0000FF00,0x00FF0000,0xFF000000); if (icon_surface) { SDL_SetWindowIcon(sdl_window, icon_surface); SDL_FreeSurface(icon_surface); } SDL_SetWindowMinimumSize(sdl_window, 320, 240); sdl_context = SDL_GL_CreateContext(sdl_window); if (!sdl_context) { Com_Printf("Couldn't create OpenGL context: %s\n", SDL_GetError()); return; } r_swapInterval.modified = true; if (!SDL_GetWindowDisplayMode(sdl_window, &display_mode)) glConfig.displayFrequency = display_mode.refresh_rate; else glConfig.displayFrequency = 0; glConfig.colorBits = 24; // FIXME SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &glConfig.depthBits); SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &glConfig.stencilBits); glConfig.vendor_string = glGetString(GL_VENDOR); glConfig.renderer_string = glGetString(GL_RENDERER); glConfig.version_string = glGetString(GL_VERSION); glConfig.extensions_string = glGetString(GL_EXTENSIONS); glConfig.initialized = true; #if defined(__linux__) InitSig(); // not clear why this is at begin & end of function #endif }