bool SDL::getAllVideoModes(StringVect &modeList) { std::set<std::string> modes; for (int display = 0; display < 100; display ++) { const int numModes = SDL_GetNumDisplayModes(display); if (numModes > 0) { logger->log("Modes for display %d", display); for (int f = 0; f < numModes; f ++) { SDL_DisplayMode mode; SDL_GetDisplayMode(display, f, &mode); const int w = mode.w; const int h = mode.h; logger->log("%dx%dx%d", w, h, mode.refresh_rate); modes.insert(strprintf("%dx%d", w, h)); } } } FOR_EACH (std::set<std::string>::const_iterator, it, modes) modeList.push_back(*it); return true; }
int SDL_VideoModeOK(int width, int height, int bpp, Uint32 flags) { int i, actual_bpp = 0; if (!SDL_GetVideoDevice()) { return 0; } if (!(flags & SDL_FULLSCREEN)) { SDL_DisplayMode mode; SDL_GetDesktopDisplayMode(GetVideoDisplay(), &mode); return SDL_BITSPERPIXEL(mode.format); } for (i = 0; i < SDL_GetNumDisplayModes(GetVideoDisplay()); ++i) { SDL_DisplayMode mode; SDL_GetDisplayMode(GetVideoDisplay(), i, &mode); if (!mode.w || !mode.h || (width == mode.w && height == mode.h)) { if (!mode.format) { return bpp; } if (SDL_BITSPERPIXEL(mode.format) >= (Uint32) bpp) { actual_bpp = SDL_BITSPERPIXEL(mode.format); } } } return actual_bpp; }
static void AddSupportedGraphicsModes(GraphicsDevice *device) { // TODO: multiple window support? const int numDisplayModes = SDL_GetNumDisplayModes(0); if (numDisplayModes < 1) { LOG(LM_GFX, LL_ERROR, "no valid display modes: %s", SDL_GetError()); return; } for (int i = 0; i < numDisplayModes; i++) { SDL_DisplayMode mode; if (SDL_GetDisplayMode(0, i, &mode) != 0) { LOG(LM_GFX, LL_ERROR, "cannot get display mode: %s", SDL_GetError()); continue; } if (mode.w < 320 || mode.h < 240) { break; } AddGraphicsMode(device, mode.w, mode.h); } }
static int lua_SDL_GetDisplayModes(lutok::state& state){ Lua_SDL_DisplayMode & dm = LOBJECT_INSTANCE(Lua_SDL_DisplayMode); Lua_SDL_Rect & r = LOBJECT_INSTANCE(Lua_SDL_Rect); state.new_table();// displays for (int display=0; display < SDL_GetNumVideoDisplays(); display++){ state.push_integer(display+1); state.new_table(); //display int modes=1; state.push_literal("modes"); state.new_table(); //modes for (int i=0; i<SDL_GetNumDisplayModes(display); i++){ SDL_DisplayMode * mode = new SDL_DisplayMode; if (SDL_GetDisplayMode(display, i, mode) == 0){ state.push_integer(modes++); dm.push(mode); state.set_table(); }else{ delete mode; } } state.set_table(); SDL_Rect * rect = new SDL_Rect; SDL_GetDisplayBounds(display, rect); state.push_literal("bounds"); r.push(rect); state.set_table(); state.set_table(); } return 1; }
PODVector<IntVector2> Graphics::GetResolutions() const { PODVector<IntVector2> ret; // Emscripten is not able to return a valid list #ifndef __EMSCRIPTEN__ unsigned numModes = (unsigned)SDL_GetNumDisplayModes(0); for (unsigned i = 0; i < numModes; ++i) { SDL_DisplayMode mode; SDL_GetDisplayMode(0, i, &mode); int width = mode.w; int height = mode.h; // Store mode if unique bool unique = true; for (unsigned j = 0; j < ret.Size(); ++j) { if (ret[j].x_ == width && ret[j].y_ == height) { unique = false; break; } } if (unique) ret.Push(IntVector2(width, height)); } #endif return ret; }
bool autoWindowSize(int& width, int& height) override { std::vector<WindowMode> res; int num_displays = SDL_GetNumVideoDisplays(); if(num_displays < 0) { LOG_ERROR("Error enumerating number of displays: " << std::string(SDL_GetError())); return false; } for(int n = 0; n != num_displays; ++n) { SDL_Rect display_bounds; SDL_GetDisplayBounds(n, &display_bounds); int num_modes = SDL_GetNumDisplayModes(n); if(num_modes < 0) { LOG_ERROR("Error enumerating number of display modes for display " << n << ": " << std::string(SDL_GetError())); return false; } for(int m = 0; m != num_modes; ++m) { SDL_DisplayMode mode; int err = SDL_GetDisplayMode(n, m, &mode); if(err < 0) { LOG_ERROR("Couldn't get display mode information for display: " << n << " mode: " << m << " : " << std::string(SDL_GetError())); } else { WindowMode new_mode = { mode.w, mode.h, std::make_shared<SDLPixelFormat>(mode.format), mode.refresh_rate }; res.emplace_back(new_mode); LOG_DEBUG("added mode w: " << mode.w << ", h: " << mode.h << ", refresh: " << mode.refresh_rate); } } } if(!res.empty()) { width = static_cast<int>(res.front().width * 0.8f); height = static_cast<int>(res.front().height * 0.8f); return true; } return false; }
/* =============== GLimp_DetectAvailableModes =============== */ static bool GLimp_DetectAvailableModes(void) { int i; char buf[ MAX_STRING_CHARS ] = { 0 }; SDL_Rect modes[ 128 ]; int numModes = 0; int display = SDL_GetWindowDisplayIndex( screen ); SDL_DisplayMode windowMode; if( SDL_GetWindowDisplayMode( screen, &windowMode ) < 0 ) { Com_Printf( "Couldn't get window display mode, no resolutions detected (%s).\n", SDL_GetError() ); return false; } int numDisplayModes = SDL_GetNumDisplayModes( display ); for( i = 0; i < numDisplayModes; i++ ) { SDL_DisplayMode mode; if( SDL_GetDisplayMode( display, i, &mode ) < 0 ) continue; if( !mode.w || !mode.h ) { Com_Printf( "Display supports any resolution\n" ); return true; } if( windowMode.format != mode.format ) continue; modes[ numModes ].w = mode.w; modes[ numModes ].h = mode.h; numModes++; } if( numModes > 1 ) qsort( modes, numModes, sizeof( SDL_Rect ), GLimp_CompareModes ); for( i = 0; i < numModes; i++ ) { const char *newModeString = va( "%ux%u ", modes[ i ].w, modes[ i ].h ); if( strlen( newModeString ) < (int)sizeof( buf ) - strlen( buf ) ) Q_strcat( buf, sizeof( buf ), newModeString ); else Com_Printf( "Skipping mode %ux%x, buffer too small\n", modes[ i ].w, modes[ i ].h ); } if( *buf ) { buf[ strlen( buf ) - 1 ] = 0; Com_Printf( "Available modes: '%s'\n", buf ); ri->Cvar_Set( "r_availableModes", buf ); } return true; }
void VID_Init (void) { int i; // Enumerate modes. vid_num_modes = SDL_min(VID_MAX_MODES, SDL_GetNumDisplayModes(0)); for (i = 0; i < vid_num_modes; ++i) { SDL_DisplayMode mode = { 0 }; SDL_GetDisplayMode(0, i, &mode); vid_modes[i].width = mode.w; vid_modes[i].height = mode.h; } qsort(&vid_modes[0], vid_num_modes, sizeof(vidmode_t), &CompareModes); /* Create the video variables so we know how to start the graphics drivers */ vid_ref = Cvar_Get ("vid_ref", "gl", CVAR_ARCHIVE); vid_fullscreen = Cvar_Get ("vid_fullscreen", "0", CVAR_ARCHIVE); vid_gamma = Cvar_Get( "vid_gamma", "1", CVAR_ARCHIVE ); /* Add some console commands that we want to handle */ Cmd_AddCommand ("vid_restart", VID_Restart_f); /* Start the graphics mode and load refresh DLL */ VID_CheckChanges(); }
void Window::SetMaxMinResolution( SDL_Window * window, int &min_width, int &min_height, int &max_width, int &max_height ){ if( window == NULL or window == nullptr ){ return; } int DisplayIndex = SDL_GetWindowDisplayIndex( window ); SDL_DisplayMode CurrentDisplayMode; if( SDL_GetDisplayMode( DisplayIndex, SDL_GetNumDisplayModes( DisplayIndex ) - 1, &CurrentDisplayMode ) == 0 ){ min_width = CurrentDisplayMode.w; min_height = CurrentDisplayMode.h; logger << ( "[LOG] Minimal resolution: " + to_string( min_width ) + "x" + to_string( min_height ) ); } else{ logger << ( "[ERROR] SDL_GetDisplayMode: " + string( SDL_GetError() ) ); return; } SDL_SetWindowMinimumSize( window, min_width, min_height ); if( SDL_GetDisplayMode( DisplayIndex, 0, &CurrentDisplayMode ) == 0 ){ max_width = CurrentDisplayMode.w; max_height = CurrentDisplayMode.h; logger << ( "[LOG] Maximal resolution: " + to_string( max_width ) + "x" + to_string( max_height ) ); } else{ logger << ( "[ERROR] SDL_GetDisplayMode: " + string( SDL_GetError() ) ); return; } SDL_SetWindowMaximumSize( window, max_width, max_height ); }
static UINT WINAPI d3dadapter9_GetAdapterModeCount( struct d3dadapter9 *This, UINT Adapter, D3DFORMAT Format ) { if (Adapter >= d3dadapter9_GetAdapterCount(This)) { WARN("Adapter %u does not exist.\n", Adapter); return 0; } if (FAILED(d3dadapter9_CheckDeviceFormat(This, Adapter, D3DDEVTYPE_HAL, Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, Format))) { WARN("DeviceFormat not available.\n"); return 0; } int NumMatchingModes = 0; int NumModes = SDL_GetNumDisplayModes(Adapter); int i; for (i=0;i<NumModes;i++) { SDL_DisplayMode mode; int err = SDL_GetDisplayMode(Adapter, i, &mode); if (err < 0) { WARN("SDL_GetDisplayMode returned an error: %s\n", SDL_GetError()); return 0; } if (Format == ConvertFromSDL(mode.format)) NumMatchingModes ++; } return NumMatchingModes; }
std::vector<SDL_DisplayMode> Display::get_fullscreen_video_modes() { std::vector<SDL_DisplayMode> video_modes; int num_displays = SDL_GetNumVideoDisplays(); log_info("number of displays: %1%", num_displays); for(int display = 0; display < num_displays; ++display) { int num_modes = SDL_GetNumDisplayModes(display); for (int i = 0; i < num_modes; ++i) { SDL_DisplayMode mode; if (SDL_GetDisplayMode(display, i, &mode) != 0) { log_error("failed to get display mode: %1%", SDL_GetError()); } else { log_debug("%1%x%2%@%3% %4%", mode.w, mode.h, mode.refresh_rate, SDL_GetPixelFormatName(mode.format)); video_modes.push_back(mode); } } } return video_modes; }
std::vector<VideoMode> GetAvailableVideoModes() { std::vector<VideoMode> modes; const int num_displays = SDL_GetNumVideoDisplays(); for(int display_index = 0; display_index < num_displays; display_index++) { const int num_modes = SDL_GetNumDisplayModes(display_index); SDL_Rect display_bounds; SDL_GetDisplayBounds(display_index, &display_bounds); for (int display_mode = 0; display_mode < num_modes; display_mode++) { SDL_DisplayMode mode; SDL_GetDisplayMode(display_index, display_mode, &mode); // insert only if unique resolution if( modes.end()==std::find(modes.begin(), modes.end(), VideoMode(mode.w, mode.h)) ) { modes.push_back(VideoMode(mode.w, mode.h)); } } } if( num_displays==0 ) { modes.push_back(VideoMode(800, 600)); } return modes; }
int32_t get_display_mode(int32_t *wx, int32_t *wy) { static int32_t display_in_use = 0; /* Only using first display */ int32_t i; int32_t display_mode_count; SDL_DisplayMode mode; display_mode_count = SDL_GetNumDisplayModes(display_in_use); if (display_mode_count < 1) return (0); i = 0; while (i < display_mode_count) { if (SDL_GetDisplayMode(display_in_use, i, &mode) != 0) { SDL_Log("SDL_GetDisplayMode failed: %s", SDL_GetError()); return (0); } if (i == 0) { *wx = mode.w; *wy = mode.h; } ++i; } return (1); }
static void BuildFullscreenModesList(void) { screen_mode_t *m1; screen_mode_t *m2; screen_mode_t m; int display = 0; // SDL2-TODO int num_modes; int i; // Free the existing modes list, if one exists if (screen_modes_fullscreen != NULL) { free(screen_modes_fullscreen); } num_modes = SDL_GetNumDisplayModes(display); screen_modes_fullscreen = calloc(num_modes, sizeof(screen_mode_t) + 1); for (i = 0; i < SDL_GetNumDisplayModes(display); ++i) { SDL_DisplayMode mode; SDL_GetDisplayMode(display, i, &mode); screen_modes_fullscreen[i].w = mode.w; screen_modes_fullscreen[i].h = mode.h; // SDL2-TODO: Deal with duplicate modes due to different pixel formats. } screen_modes_fullscreen[num_modes].w = 0; screen_modes_fullscreen[num_modes].h = 0; // Reverse the order of the modes list (smallest modes first) for (i=0; i<num_modes / 2; ++i) { m1 = &screen_modes_fullscreen[i]; m2 = &screen_modes_fullscreen[num_modes - 1 - i]; memcpy(&m, m1, sizeof(screen_mode_t)); memcpy(m1, m2, sizeof(screen_mode_t)); memcpy(m2, &m, sizeof(screen_mode_t)); } num_screen_modes_fullscreen = num_modes; }
bool CheckAvailableVideoModes() { // Get available fullscreen/hardware modes const int numDisplays = SDL_GetNumVideoDisplays(); SDL_DisplayMode ddm = {0, 0, 0, 0, nullptr}; SDL_DisplayMode cdm = {0, 0, 0, 0, nullptr}; // ddm is virtual, contains all displays in multi-monitor setups // for fullscreen windows with non-native resolutions, ddm holds // the original screen mode and cdm is the changed mode SDL_GetDesktopDisplayMode(0, &ddm); SDL_GetCurrentDisplayMode(0, &cdm); LOG( "[GL::%s] desktop={%ix%ix%ibpp@%iHz} current={%ix%ix%ibpp@%iHz}", __func__, ddm.w, ddm.h, SDL_BPP(ddm.format), ddm.refresh_rate, cdm.w, cdm.h, SDL_BPP(cdm.format), cdm.refresh_rate ); for (int k = 0; k < numDisplays; ++k) { const int numModes = SDL_GetNumDisplayModes(k); if (numModes <= 0) { LOG("\tdisplay=%d bounds=N/A modes=N/A", k + 1); continue; } SDL_DisplayMode cm = {0, 0, 0, 0, nullptr}; SDL_DisplayMode pm = {0, 0, 0, 0, nullptr}; SDL_Rect db; SDL_GetDisplayBounds(k, &db); LOG("\tdisplay=%d modes=%d bounds={x=%d, y=%d, w=%d, h=%d}", k + 1, numModes, db.x, db.y, db.w, db.h); for (int i = 0; i < numModes; ++i) { SDL_GetDisplayMode(k, i, &cm); const float r0 = (cm.w * 9.0f) / cm.h; const float r1 = (cm.w * 10.0f) / cm.h; const float r2 = (cm.w * 16.0f) / cm.h; // skip legacy (3:2, 4:3, 5:4, ...) and weird (10:6, ...) ratios if (r0 != 16.0f && r1 != 16.0f && r2 != 25.0f) continue; // show only the largest refresh-rate and bit-depth per resolution if (cm.w == pm.w && cm.h == pm.h && (SDL_BPP(cm.format) < SDL_BPP(pm.format) || cm.refresh_rate < pm.refresh_rate)) continue; LOG("\t\t[%2i] %ix%ix%ibpp@%iHz", int(i + 1), cm.w, cm.h, SDL_BPP(cm.format), cm.refresh_rate); pm = cm; } } // we need at least 24bpp or window-creation will fail return (SDL_BPP(ddm.format) >= 24); }
bool SDL2Window::initializeFramework() { arx_assert(s_mainWindow == NULL, "SDL only supports one window"); // TODO it supports multiple windows now! arx_assert(m_displayModes.empty()); const char * headerVersion = ARX_STR(SDL_MAJOR_VERSION) "." ARX_STR(SDL_MINOR_VERSION) "." ARX_STR(SDL_PATCHLEVEL); CrashHandler::setVariable("SDL version (headers)", headerVersion); if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) { LogError << "Failed to initialize SDL: " << SDL_GetError(); return false; } #ifdef ARX_DEBUG // No SDL, this is more annoying than helpful! #if defined(SIGINT) signal(SIGINT, SIG_DFL); #endif #if defined(SIGTERM) signal(SIGTERM, SIG_DFL); #endif #endif SDL_version ver; SDL_GetVersion(&ver); std::ostringstream runtimeVersion; runtimeVersion << int(ver.major) << '.' << int(ver.minor) << '.' << int(ver.patch); CrashHandler::setVariable("SDL version (runtime)", runtimeVersion.str()); LogInfo << "Using SDL " << runtimeVersion.str(); int ndisplays = SDL_GetNumVideoDisplays(); for(int display = 0; display < ndisplays; display++) { int modes = SDL_GetNumDisplayModes(display); for(int i = 0; i < modes; i++) { SDL_DisplayMode mode; if(SDL_GetDisplayMode(display, i, &mode) >= 0) { m_displayModes.push_back(Vec2i(mode.w, mode.h)); } } } std::sort(m_displayModes.begin(), m_displayModes.end()); m_displayModes.erase(std::unique(m_displayModes.begin(), m_displayModes.end()), m_displayModes.end()); s_mainWindow = this; SDL_SetEventFilter(eventFilter, NULL); SDL_EventState(SDL_WINDOWEVENT, SDL_ENABLE); SDL_EventState(SDL_QUIT, SDL_ENABLE); SDL_EventState(SDL_SYSWMEVENT, SDL_IGNORE); SDL_EventState(SDL_USEREVENT, SDL_IGNORE); return true; }
/* =============== GLimp_DetectAvailableModes =============== */ static void GLimp_DetectAvailableModes() { char buf[MAX_STRING_CHARS] = {0}; SDL_Rect modes[128]; int numModes = 0; int i; SDL_DisplayMode windowMode; int display; display = SDL_GetWindowDisplayIndex(window); if (SDL_GetWindowDisplayMode(window, &windowMode) < 0) { ri.Printf(PRINT_WARNING, "Couldn't get window display mode: %s\n", SDL_GetError()); return; } for (i = 0; i < SDL_GetNumDisplayModes(display); i++) { SDL_DisplayMode mode; if (SDL_GetDisplayMode(display, i, &mode) < 0) { continue; } if (!mode.w || !mode.h) { ri.Printf(PRINT_ALL, "Display supports any resolution\n"); return; } if (windowMode.format != mode.format || windowMode.refresh_rate != mode.refresh_rate) { continue; } modes[numModes].w = mode.w; modes[numModes].h = mode.h; numModes++; } if (numModes > 1) { qsort(modes, numModes, sizeof(SDL_Rect), GLimp_CompareModes); } for (i = 0; i < numModes; i++) { const char* newModeString = va("%ux%u ", modes[i].w, modes[i].h); if (strlen(newModeString) < (int) sizeof(buf) - strlen(buf)) { Q_strcat(buf, sizeof(buf), newModeString); } else { ri.Printf(PRINT_WARNING, "Skipping mode %ux%x, buffer too small\n", modes[i].w, modes[i].h); } } if (*buf) { ri.Printf(PRINT_ALL, "Available modes: '%s'\n", buf); ri.Cvar_Set("r_availableModes", buf); } }
void SDLGameWindow::OutputDisplayModes() { int numModes = SDL_GetNumDisplayModes(0); for (int i = 0; i < numModes; i++) { SDL_DisplayMode mode; SDL_GetDisplayMode(0, i, &mode); DebugPrintF(VTEXT("DisplayMode[%i]: <W: %i, H: %i>\n"), i, mode.w, mode.h); } }
int main(int argc, char *argv[]) { SDL_DisplayMode mode; int num_displays, dpy; /* Enable standard application logging */ SDL_LogSetPriority(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO); /* Load the SDL library */ if (SDL_Init(SDL_INIT_VIDEO) < 0) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s\n", SDL_GetError()); return 1; } SDL_Log("Using video target '%s'.\n", SDL_GetCurrentVideoDriver()); num_displays = SDL_GetNumVideoDisplays(); SDL_Log("See %d displays.\n", num_displays); for (dpy = 0; dpy < num_displays; dpy++) { const int num_modes = SDL_GetNumDisplayModes(dpy); SDL_Rect rect = { 0, 0, 0, 0 }; int m; SDL_GetDisplayBounds(dpy, &rect); SDL_Log("%d: \"%s\" (%dx%d, (%d, %d)), %d modes.\n", dpy, SDL_GetDisplayName(dpy), rect.w, rect.h, rect.x, rect.y, num_modes); if (SDL_GetCurrentDisplayMode(dpy, &mode) == -1) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " CURRENT: failed to query (%s)\n", SDL_GetError()); } else { print_mode("CURRENT", &mode); } if (SDL_GetDesktopDisplayMode(dpy, &mode) == -1) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " DESKTOP: failed to query (%s)\n", SDL_GetError()); } else { print_mode("DESKTOP", &mode); } for (m = 0; m < num_modes; m++) { if (SDL_GetDisplayMode(dpy, m, &mode) == -1) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, " MODE %d: failed to query (%s)\n", m, SDL_GetError()); } else { char prefix[64]; SDL_snprintf(prefix, sizeof (prefix), " MODE %d", m); print_mode(prefix, &mode); } } SDL_Log("\n"); } return 0; }
static HRESULT WINAPI d3dadapter9_EnumAdapterModes( struct d3dadapter9 *This, UINT Adapter, D3DFORMAT Format, UINT ModeIndex, D3DDISPLAYMODE *pMode ) { HRESULT hr; if (Adapter >= d3dadapter9_GetAdapterCount(This)) { WARN("Adapter %u does not exist.\n", Adapter); return D3DERR_INVALIDCALL; } if (!pMode) { WARN("pMode is NULL.\n"); return D3DERR_INVALIDCALL; } hr = d3dadapter9_CheckDeviceFormat(This, Adapter, D3DDEVTYPE_HAL, Format, D3DUSAGE_RENDERTARGET, D3DRTYPE_SURFACE, Format); if (FAILED(hr)) { TRACE("DeviceFormat not available.\n"); return hr; } int IndexMatchingModes = 0; int NumModes = SDL_GetNumDisplayModes(Adapter); int i; for (i=0;i<NumModes;i++) { SDL_DisplayMode mode; int err = SDL_GetDisplayMode(Adapter, i, &mode); if (err < 0) { WARN("SDL_GetDisplayMode returned an error: %s\n", SDL_GetError()); return D3DERR_INVALIDCALL; } if (Format != ConvertFromSDL(mode.format)) continue; if (IndexMatchingModes == ModeIndex) { TRACE("DiplayMode: %dx%d@%dHz, d3dformat=%d\n", mode.w, mode.h, mode.refresh_rate, Format); pMode->Width = mode.w; pMode->Height = mode.h; pMode->RefreshRate = mode.refresh_rate; pMode->Format = Format; return D3D_OK; } IndexMatchingModes ++; } WARN("invalid mode for format %d on adapter %d: %d\n", Format, Adapter, ModeIndex); return D3DERR_INVALIDCALL; }
static void VID_SetupModeList(void) { int i; Q_free(modelist); modelist_count = SDL_GetNumDisplayModes(0); modelist = Q_calloc(modelist_count, sizeof(*modelist)); for (i = 0; i < modelist_count; i++) { SDL_GetDisplayMode(0, i, &modelist[i]); } }
Display ( unsigned int index): index(index) { name = SDL_GetDisplayName(index); int numDisplayModes = SDL_GetNumDisplayModes(index); for (int i = 0; i < numDisplayModes; ++i) { SDL_DisplayMode displayMode; if (SDL_GetDisplayMode(index, i, &displayMode) != -1) { displayModes.push_back(DisplayMode(i, displayMode)); } } }
Vector<SDL_DisplayMode> Renderer::EnumerateDisplayModes() const { // Enumerate available video modes Vector<SDL_DisplayMode> displayModes; int count = SDL_GetNumDisplayModes(0); for (int i = 0; i < count; ++i) { SDL_DisplayMode mode; SDL_GetDisplayMode(0, i, &mode); displayModes.push_back(mode); } return displayModes; }
//-------------------------------------------------------------------------------------------- bool SDLX_Get_Screen_Info( SDLX_screen_info_t& psi, bool make_report ) { Uint32 init_flags = 0; SDL_Window *window; init_flags = SDL_WasInit( SDL_INIT_EVERYTHING ); if ( 0 == init_flags ) { if ( make_report ) Log::get().message("ERROR: SDLX_Get_Screen_Info() called before initializing SDL\n"); return false; } else if ( HAS_NO_BITS( init_flags, SDL_INIT_VIDEO ) ) { if ( make_report ) Log::get().message("ERROR: SDLX_Get_Screen_Info() called before initializing SDL video driver\n"); return false; } // store the screen info for everyone to use window = Ego::GraphicsSystem::window; psi.window = window; SDL_GetWindowSize(window, &(psi.x), &(psi.y)); SDLX_GetDrawableSize(window, &(psi.drawWidth), &(psi.drawHeight)); // Grab all the available video modes psi.video_mode_list.clear(); int displayNum = SDL_GetWindowDisplayIndex(window); int numDisplayModes = SDL_GetNumDisplayModes(displayNum); for (int i = 0; i < numDisplayModes; i++) { SDL_DisplayMode mode; SDL_GetDisplayMode(displayNum, i, &mode); psi.video_mode_list.push_back(mode); } // log the video driver info psi.szDriver = SDL_GetCurrentVideoDriver(); // grab all SDL_GL_* attributes SDLX_sdl_gl_attrib_t::download(psi.gl_att); // translate the surface flags into the bitfield SDLX_sdl_video_flags_t::download(psi.flags, SDL_GetWindowFlags(window)); if (make_report) { SDLX_screen_info_t::report(psi); } return true; }
/* =============== GLimp_DetectAvailableModes =============== */ static void GLimp_DetectAvailableModes(void) { char buf[ MAX_STRING_CHARS ] = { 0 }; //SDL_Rect **modes; int numModes; int i; SDL_DisplayMode displayMode; /*modes = SDL_ListModes( NULL, SDL_OPENGL | SDL_FULLSCREEN ); if( !modes ) { ri.Printf( PRINT_WARNING, "Can't get list of available modes\n" ); return; } if( modes == (SDL_Rect **)-1 )*/ if( (numModes = SDL_GetNumDisplayModes( 0 )) <= 0 )//FIXME: Use SDL_GetWindowDisplayIndex instead of 0? { ri.Printf( PRINT_DEVELOPER, "Display supports any resolution\n" ); return; // can set any resolution } /*for( numModes = 0; modes[ numModes ]; numModes++ ); if(numModes > 1) qsort( modes+1, numModes-1, sizeof( SDL_Rect* ), GLimp_CompareModes );*/ for( i = 0; i < numModes; i++ ) { const char *newModeString; if( SDL_GetDisplayMode( 0, i, &displayMode ) != 0 ) { break; } newModeString = va( "%ux%u ", displayMode.w, displayMode.h ); if( strlen( newModeString ) < (int)sizeof( buf ) - strlen( buf ) ) Q_strcat( buf, sizeof( buf ), newModeString ); else ri.Printf( PRINT_WARNING, "Skipping mode %ux%x, buffer too small\n", displayMode.w, displayMode.h ); } if( *buf ) { buf[ strlen( buf ) - 1 ] = 0; ri.Printf( PRINT_DEVELOPER, "Available modes: '%s'\n", buf ); ri.Cvar_Set( "r_availableModes", buf ); } }
/*static*/ void Display::EnumerateDisplayModes( Array<SDisplayMode>& DisplayModes ) { DisplayModes.Clear(); #if BUILD_WINDOWS_NO_SDL DEVMODE DevMode; uint ModeIndex = 0; BOOL Valid = TRUE; for( ; Valid; ++ModeIndex ) { Valid = EnumDisplaySettings( NULL, ModeIndex, &DevMode ); // Some users have problems if their refresh rate is set to 59 Hz. Maybe I should reconsider this? if( DevMode.dmBitsPerPel == 32 ) { SDisplayMode Mode; Mode.Width = DevMode.dmPelsWidth; Mode.Height = DevMode.dmPelsHeight; DisplayModes.PushBackUnique( Mode ); } } #endif #if BUILD_SDL PRINTF( "Enumerating SDL display modes...\n" ); const int NumDisplays = SDL_GetNumVideoDisplays(); for( int DisplayIndex = 0; DisplayIndex < NumDisplays; ++DisplayIndex ) { const int NumModes = SDL_GetNumDisplayModes( DisplayIndex ); for( int ModeIndex = 0; ModeIndex < NumModes; ++ModeIndex ) { SDL_DisplayMode DisplayMode; SDL_GetDisplayMode( DisplayIndex, ModeIndex, &DisplayMode ); if( SDL_BYTESPERPIXEL( DisplayMode.format ) == 4 ) { SDisplayMode Mode; Mode.Width = DisplayMode.w; Mode.Height = DisplayMode.h; DisplayModes.PushBackUnique( Mode ); PRINTF( "Enumerated mode %dx%d\n", Mode.Width, Mode.Height ); } } } #endif ASSERT( DisplayModes.Size() ); }
SDL_DisplayMode mode_auto_select() { SDL_DisplayMode mode; //uncomment out when support for SDL_GetWindowDisplayIndex stabilizes. const int display_index = 0; //SDL_GetWindowDisplayIndex(graphics::get_window()); SDL_GetDesktopDisplayMode(display_index, &mode); if(preferences::fullscreen()) { return mode; } std::cerr << "CURRENT MODE IS " << mode.w << "x" << mode.h << "\n"; SDL_DisplayMode best_mode = mode; if(preferences::fullscreen() == false && mode.w > 1024 && mode.h > 768) { const int nmodes = SDL_GetNumDisplayModes(display_index); for(int n = 0; n != nmodes; ++n) { SDL_DisplayMode candidate_mode; const int nvalue = SDL_GetDisplayMode(display_index, n, &candidate_mode); if(nvalue != 0) { std::cerr << "ERROR QUERYING DISPLAY INFO: " << SDL_GetError() << "\n"; continue; } const float MinReduction = 0.9f; if(candidate_mode.w < mode.w && candidate_mode.h < mode.w && candidate_mode.w < mode.w*MinReduction && candidate_mode.h < mode.h*MinReduction && (candidate_mode.w >= best_mode.w && candidate_mode.h >= best_mode.h || best_mode.w == mode.w && best_mode.h == mode.h)) { std::cerr << "BETTER MODE IS " << candidate_mode.w << "x" << candidate_mode.h << "\n"; best_mode = candidate_mode; } else { std::cerr << "REJECTED MODE IS " << candidate_mode.w << "x" << candidate_mode.h << "\n"; } } } if(best_mode.w < g_min_window_width || best_mode.h < g_min_window_height) { best_mode.w = g_min_window_width; best_mode.h = g_min_window_height; } return best_mode; }
void CApplication::initVideoModes() { SDL_DisplayMode mode; int numDisplay = SDL_GetNumVideoDisplays(); for( int i = 0; i < numDisplay; ++i ) { int displayModes = SDL_GetNumDisplayModes(0); for( int j = 0; j < displayModes; ++j ) { SDL_GetDisplayMode(i, j, &mode); m_DisplayModes[i+1].push_back(mode); } } }
int bbSDLGraphicsGraphicsModes( int display, int *imodes,int maxcount ) { SDL_DisplayMode mode; int count,i; count = SDL_GetNumDisplayModes(display); if (count>maxcount) count=maxcount; for (i=0;i<count;i++) { SDL_GetDisplayMode(display, i, &mode); *imodes++=mode.w; *imodes++=mode.h; *imodes++=SDL_BITSPERPIXEL(mode.format); *imodes++=mode.refresh_rate; } return count; }
QStringList SDLInteraction::getResolutions() const { QStringList result; int modesNumber = SDL_GetNumDisplayModes(0); SDL_DisplayMode mode; for(int i = 0; i < modesNumber; ++i) { SDL_GetDisplayMode(0, i, &mode); if ((mode.w >= 640) && (mode.h >= 480)) result << QString("%1x%2").arg(mode.w).arg(mode.h); } return result; }