当前位置: 首页>>代码示例>>C++>>正文


C++ SDL_GetNumDisplayModes函数代码示例

本文整理汇总了C++中SDL_GetNumDisplayModes函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_GetNumDisplayModes函数的具体用法?C++ SDL_GetNumDisplayModes怎么用?C++ SDL_GetNumDisplayModes使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了SDL_GetNumDisplayModes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SDL_GetNumDisplayModes

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;
}
开发者ID:KaneHart,项目名称:Elmlor-Client,代码行数:25,代码来源:sdl2helper.cpp

示例2: SDL_VideoModeOK

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;
}
开发者ID:Blitzoreo,项目名称:pcsx2-online,代码行数:29,代码来源:SDL_compat.c

示例3: AddSupportedGraphicsModes

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);
    }
}
开发者ID:cxong,项目名称:cdogs-sdl,代码行数:25,代码来源:grafx.c

示例4: lua_SDL_GetDisplayModes

	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;
	}
开发者ID:swc4848a,项目名称:LuaSDL-2.0,代码行数:34,代码来源:video.cpp

示例5:

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;
}
开发者ID:TheComet93,项目名称:Urho3D,代码行数:32,代码来源:Graphics.cpp

示例6: autoWindowSize

		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;
		}
开发者ID:sweetkristas,项目名称:render_engine,代码行数:35,代码来源:WindowManager.cpp

示例7: GLimp_DetectAvailableModes

/*
===============
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;
}
开发者ID:Wookiee-,项目名称:jaPRO,代码行数:65,代码来源:sdl_glimp.cpp

示例8: VID_Init

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();
}
开发者ID:petmac,项目名称:quake2-lite,代码行数:29,代码来源:vid_sdl.c

示例9: SDL_GetWindowDisplayIndex

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 );
}
开发者ID:kaczla,项目名称:OpenGL,代码行数:30,代码来源:window.cpp

示例10: d3dadapter9_GetAdapterModeCount

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;
}
开发者ID:EoD,项目名称:Xnine,代码行数:33,代码来源:SDL_nine.c

示例11: SDL_GetNumVideoDisplays

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;
}
开发者ID:drewbug,项目名称:pingus,代码行数:29,代码来源:display.cpp

示例12: GetAvailableVideoModes

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;
}
开发者ID:Action-Committee,项目名称:pioneer,代码行数:27,代码来源:Graphics.cpp

示例13: get_display_mode

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);
}
开发者ID:42rdavid,项目名称:Opengl-GOL,代码行数:27,代码来源:get_display_mode.c

示例14: BuildFullscreenModesList

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;
}
开发者ID:derek57,项目名称:research,代码行数:46,代码来源:display.c

示例15: CheckAvailableVideoModes

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%[email protected]%iHz} current={%ix%ix%[email protected]%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%[email protected]%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);
}
开发者ID:sprunk,项目名称:spring,代码行数:58,代码来源:myGL.cpp


注:本文中的SDL_GetNumDisplayModes函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。