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


C++ SDL_GetCurrentDisplayMode函数代码示例

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


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

示例1: SGL_CreateWindow

SGL_Window* SGL_CreateWindow(const char* title, int GLMajorVersion, int GLMinorVersion, int x, int y, int w, int h, Uint32 SDLflags)
{
#if defined(_WINDOWS)
	SDL_DisplayMode targetMode;
	if (SDL_GetCurrentDisplayMode(0, &targetMode))
	{
		return NULL;
	}
	SDL_DisplayMode closestMode;
	SDL_GetClosestDisplayMode(0, &targetMode, &closestMode);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, GLMajorVersion);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, GLMinorVersion);
	SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	SGL_Window* window = SDL_malloc(sizeof(SGL_Window));
	window->window = SDL_CreateWindow
		(
			title,
			x, y,
			w, h,
			SDLflags
		);
	window->context = SDL_GL_CreateContext(window->window);
	glewExperimental = GL_TRUE;
	glewInit();
#elif defined(ANDROID)
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, GLMajorVersion > 3 ? GLMajorVersion : 3);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
	SGL_Window* window = SDL_malloc(sizeof(SGL_Window));
	SDL_DisplayMode displayMode;
	if (SDL_GetCurrentDisplayMode(0, &displayMode))
	{
		return NULL;
	}
	window->window = SDL_CreateWindow
		(
			title,
			SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
			displayMode.w, displayMode.h,
			SDLflags
			);
	window->context = SDL_GL_CreateContext(window->window);
#endif
	SDL_Log("----------------------------------------------------------------\n");
	SDL_Log("Graphics Successfully Initialized For Window: %s\n", title);
	SDL_Log("OpenGL Info\n");
	SDL_Log("  Version: %s\n", glGetString(GL_VERSION));
	SDL_Log("   Vendor: %s\n", glGetString(GL_VENDOR));
	SDL_Log(" Renderer: %s\n", glGetString(GL_RENDERER));
	SDL_Log("  Shading: %s\n", glGetString(GL_SHADING_LANGUAGE_VERSION));
	SDL_Log("----------------------------------------------------------------\n");
	SGL_SetWindowIcon(window, NULL);
	return window;
}
开发者ID:uraani,项目名称:StercusEngine,代码行数:55,代码来源:SGL.c

示例2: SDL_CreateWindow

/*
* Create a new window
* @param windowName is the window's title
* @param windowWidth is the window's width
* @param windowHeight is the window's height
* @param fullScreen specifies if the window is full screen or not
*/
void SDLInterface::createWindow(std::string windowName, int windowWidth, int windowHeight, bool fullScreen) {
	_windowWidth = windowWidth;
	_windowHeight = windowHeight;
	
		//Update the window flags
	Uint32 flags = SDL_WINDOW_SHOWN;
	if (fullScreen) {
		flags |= SDL_WINDOW_MAXIMIZED | SDL_WINDOW_BORDERLESS;
	}	

		//Create a SDL window centered into the middle of the screen
	_window = SDL_CreateWindow(windowName.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _windowWidth, _windowHeight, flags);

		//Declare display mode structure to be filled in. It will allow us to get the current resolution
	SDL_DisplayMode current;
	SDL_GetCurrentDisplayMode(0, &current);
	_windowWidthFullScreen = current.w;
	_windowHeightFullScreen = current.h;
			
		// if the window creation succeeded create our renderer.
	if (_window != 0) {
		_renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_PRESENTVSYNC);
			// Set to black
		setWindowBackgroundColor(0, 0, 0, 255);		
	}
	else {
		ErrorManagement::errorRunTime("[SDL Interface] A problem occurred when the window was created");
	}	
}
开发者ID:DagorladFinite,项目名称:Steeplechase,代码行数:36,代码来源:SDLInterface.cpp

示例3: assert

	void SDLWindow::Initialize()
	{
		assert(((start_location.w > 0 && start_location.h > 0) || start_location.w == start_location.h),
			"If a special resolution modifier is to be used, then both length and width must be equal.");

		if (start_location == USE_CURRENT_RESOLUTION)
		{
			SDL_DisplayMode display_mode;

			assert((SDL_GetCurrentDisplayMode(DISPLAY_NUMBER, &display_mode) == 0), SDL_GetError());

			start_location.w = (double)display_mode.w;
			start_location.h = (double)display_mode.h;
		}

		if (fullscreen)
		{
			SDL_CreateWindowAndRenderer(0, 0,
				(SDL_WINDOW_FULLSCREEN_DESKTOP | SDL_WINDOW_BORDERLESS),
				&window, &write_to);
			// Scale so the user's code doesn't know the difference.
			SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "linear");  // make the scaled rendering look smoother.
			SDL_RenderSetLogicalSize(write_to, GfxRound(start_location.w), GfxRound(start_location.h));
		}
		else
		{
			SDL_CreateWindowAndRenderer(GfxRound(start_location.w), GfxRound(start_location.h), 0, &window, &write_to);
		}

		SDL_SetWindowTitle(this->window, this->title);

		SDL_SetRenderDrawColor(write_to, fill.r, fill.g, fill.b, fill.a);
		SDL_RenderClear(write_to);
		SDL_RenderPresent(write_to);
	}
开发者ID:JackMc,项目名称:CPlasmas,代码行数:35,代码来源:SDLWindow.cpp

示例4: wid_intro_settings_add_default_screen_modes

static void wid_intro_settings_add_default_screen_modes (void)
{
    int w;
    int h;
#if SDL_MAJOR_VERSION == 2 /* { */
    SDL_DisplayMode mode;
    SDL_GetCurrentDisplayMode(0, &mode);
    w = mode.w;
    h = mode.h; 
#else
    const SDL_VideoInfo *info = SDL_GetVideoInfo();
    w = info->current_w;
    h = info->current_h; 
#endif
    char *tmp = dynprintf("%dx%d", w, h);
    int j;

    for (j = 0; j < WID_INTRO_MAX_VAL - 1; j++) {
        if (!wid_intro_button_value_string
            [WID_INTRO_SETTINGS_ROW_WINDOW][j]) {

            wid_intro_button_value_string
                [WID_INTRO_SETTINGS_ROW_WINDOW][j] = tmp;

            break;
        }
    } /* } */
}
开发者ID:goblinhack,项目名称:adventurine,代码行数:28,代码来源:wid_intro_settings.c

示例5: GetWindowSize

void cWindow::RenderAt( cSurface* pImage, cPosition pSource ) {
	SDL_Rect Src, Dest;

	Src.w = mScreenSize.mWidth;
	Src.h = mScreenSize.mHeight;
	Src.x = pSource.mX + 16;
	Src.y = pSource.mY + 16;

	Dest.w = GetWindowSize().mWidth;
	Dest.h = GetWindowSize().mHeight;

	if (mWindowMode) {
		Dest.x = 0;
		Dest.y = 0;
	}
	else {
		SDL_DisplayMode current;
		SDL_GetCurrentDisplayMode(0, &current);

		Dest.x = (current.w - Dest.w) / 2;
		Dest.y = (current.h - Dest.h) / 2;
	}
	pImage->draw();

	SDL_RenderCopy( mRenderer, pImage->GetTexture(), &Src, &Dest );
}
开发者ID:carriercomm,项目名称:openfodder,代码行数:26,代码来源:Window.cpp

示例6: getDesktopSize

Vector2 getDesktopSize( int display_index )
{
  SDL_DisplayMode current;
  // Get current display mode of all displays.
  int should_be_zero = SDL_GetCurrentDisplayMode(display_index, &current);
  return Vector2( (float)current.w, (float)current.h );
}
开发者ID:jagenjo,项目名称:TJE_Framework,代码行数:7,代码来源:utils.cpp

示例7: GfxInfo_f

static void GfxInfo_f(void)
{
	SDL_DisplayMode current;

	Com_Printf_State(PRINT_ALL, "\nGL_VENDOR: %s\n", glConfig.vendor_string );
	Com_Printf_State(PRINT_ALL, "GL_RENDERER: %s\n", glConfig.renderer_string );
	Com_Printf_State(PRINT_ALL, "GL_VERSION: %s\n", glConfig.version_string );

	if (r_showextensions.value) {
		Com_Printf_State(PRINT_ALL, "GL_EXTENSIONS: %s\n", glConfig.extensions_string);
	}

	Com_Printf_State(PRINT_ALL, "PIXELFORMAT: color(%d-bits) Z(%d-bit)\n             stencil(%d-bits)\n", glConfig.colorBits, glConfig.depthBits, glConfig.stencilBits);

	if (SDL_GetCurrentDisplayMode(VID_DisplayNumber(r_fullscreen.value), &current) != 0) {
		current.refresh_rate = 0; // print 0Hz if we run into problem fetching data
	}

	Com_Printf_State(PRINT_ALL, "MODE: %d x %d @ %d Hz ", current.w, current.h, current.refresh_rate);
	
	if (r_fullscreen.integer) {
		Com_Printf_State(PRINT_ALL, "[fullscreen]\n");
	} else {
		Com_Printf_State(PRINT_ALL, "[windowed]\n");
	}

	Com_Printf_State(PRINT_ALL, "CONRES: %d x %d\n", r_conwidth.integer, r_conheight.integer );

}
开发者ID:kostya7,项目名称:ezquake-source,代码行数:29,代码来源:vid_sdl2.c

示例8: SDL_GetCurrentDisplayMode

void Adafruit_NeoPixel::initializeSdl() {

    if (sdlInitialized) return;
    sdlInitialized = true;

    if (SDL_Init(SDL_INIT_VIDEO) != 0) posixino.fatal("SDL init failed",3);

    SDL_GetCurrentDisplayMode(SDL_DISPLAY,&current);

    calcDims();

    window = SDL_CreateWindow(
                 "Posixino",
                 windowPosX,
                 windowPosY,
                 windowWidth,
                 windowHeight,
                 SDL_WINDOW_SHOWN | SDL_WINDOW_BORDERLESS
             );

    screenSurface = SDL_GetWindowSurface(window);
    SDL_FillRect(screenSurface,NULL,0);
    SDL_UpdateWindowSurface(window);

} // initializeSdl()
开发者ID:ern0,项目名称:posixino,代码行数:25,代码来源:posixino.cpp

示例9: initialize

	void Video::initialize(const std::string& name, const std::string& icon, Console& console)
	{
		console.printLine("\n===Video initialization===");

		// Get current video mode
		SDL_DisplayMode currentVideoMode;		
		if (SDL_GetCurrentDisplayMode(0, &currentVideoMode))
		{
			D6_THROW(VideoException, std::string("Unable to determine current video mode: ") + SDL_GetError());
		}

		// Set graphics mode
		view = ViewParameters(0.1f, 100.0f, 45.0f);

#ifdef D6_DEBUG
		// Running fullscren makes switching to debugger problematic with SDL (focus is captured)
		screen = ScreenParameters(1280, 900, 32, 0, false);
#else
		screen = ScreenParameters(currentVideoMode.w, currentVideoMode.h, 32, 0, true);
#endif

		window = createWindow(name, icon, screen, console);
		glContext = createContext(screen, console);
		SDL_ShowCursor(SDL_DISABLE);
		setMode(Mode::Orthogonal);
	}
开发者ID:martin-macak,项目名称:duel6r,代码行数:26,代码来源:Video.cpp

示例10: initSDL

void initSDL()
{
	SDL_DisplayMode video_info;
	int init_flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_JOYSTICK;

	if(SDL_Init(init_flags) < 0)
	{
		printf("SDL Failed to Init!!!! (%s)\n", SDL_GetError());
		borExit(0);
	}
	SDL_ShowCursor(SDL_DISABLE);
	atexit(SDL_Quit);

#ifdef LOADGL
	if(SDL_GL_LoadLibrary(NULL) < 0)
	{
		printf("Warning: couldn't load OpenGL library (%s)\n", SDL_GetError());
	}
#endif

	SDL_GetCurrentDisplayMode(0, &video_info);
	nativeWidth = video_info.w;
	nativeHeight = video_info.h;
	printf("debug:nativeWidth, nativeHeight, bpp, Hz  %d, %d, %d, %d\n", nativeWidth, nativeHeight, SDL_BITSPERPIXEL(video_info.format), video_info.refresh_rate);

	SDL_initFramerate(&framerate_manager);
	SDL_setFramerate(&framerate_manager, 200);
}
开发者ID:DavidKnight247,项目名称:OpenBOR-for-the-GCW0,代码行数:28,代码来源:video.c

示例11: SDL_GetError

bool RWindow::initializeSDL()
{
    SDL_DisplayMode current;

    if(SDL_Init(SDL_INIT_EVERYTHING) < 0)
    {
        std::cerr << "Could not initialize SDL: " << SDL_GetError();
        std::cerr << std::endl;
        std::exit(1);
    }

    SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
    SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);

    if(SDL_GetCurrentDisplayMode(0, &current) != 0)
    {
        // In case of error...
        std::cerr << "Could not get display mode for video display: ";
        std::cerr << SDL_GetError() << std::endl;
        return false;
    }
    else
    {
        // Everything is normal
        m_width = current.w;
        m_height = current.h;
    }

    m_window = SDL_CreateWindow(
                m_title.data(),
                SDL_WINDOWPOS_UNDEFINED,
                SDL_WINDOWPOS_UNDEFINED,
                m_width, m_height,
                SDL_WINDOW_OPENGL |
                SDL_WINDOW_FULLSCREEN_DESKTOP |
                SDL_WINDOW_HIDDEN);

    if(m_window == nullptr)
    {
        std::cerr << "Could not iniialize SDL Window: " << SDL_GetError();
        std::cerr << std::endl;
        return false;
    }

    m_surface = SDL_GetWindowSurface(m_window);
    m_context = SDL_GL_CreateContext(m_window);

    //Init cursors
    m_systemCursors[0] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
    m_systemCursors[1] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
    m_systemCursors[2] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_WAIT);
    m_systemCursors[3] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_NO);
    m_systemCursors[4] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_HAND);

    for(unsigned i = 0; i < 4; ++i)
        m_customCursors[i] = nullptr;

    return true;
}
开发者ID:Sergobot,项目名称:Realio,代码行数:60,代码来源:RWindow.cpp

示例12: SDL_GetCurrentDisplayMode

void GHOST_SystemSDL::getMainDisplayDimensions(GHOST_TUns32 &width, GHOST_TUns32 &height) const
{
  SDL_DisplayMode mode;
  SDL_GetCurrentDisplayMode(0, &mode); /* note, always 0 display */
  width = mode.w;
  height = mode.h;
}
开发者ID:wangyxuan,项目名称:blender,代码行数:7,代码来源:GHOST_SystemSDL.cpp

示例13: SetScreenParmsFullscreen

static bool SetScreenParmsFullscreen( glimpParms_t parms )
{
	SDL_DisplayMode m = {0};
	int displayIdx = ScreenParmsHandleDisplayIndex( parms );
	if( displayIdx < 0 )
		return false;
		
	// get current mode of display the window should be full-screened on
	SDL_GetCurrentDisplayMode( displayIdx, &m );
	
	// change settings in that display mode according to parms
	// FIXME: check if refreshrate, width and height are supported?
	// m.refresh_rate = parms.displayHz;
	m.w = parms.width;
	m.h = parms.height;
	
	// set that displaymode
	if( SDL_SetWindowDisplayMode( window, &m ) < 0 )
	{
		common->Warning( "Couldn't set window mode for fullscreen, reason: %s", SDL_GetError() );
		return false;
	}
	
	// if we're currently not in fullscreen mode, we need to switch to fullscreen
	if( !( SDL_GetWindowFlags( window ) & SDL_WINDOW_FULLSCREEN ) )
	{
		if( SDL_SetWindowFullscreen( window, SDL_TRUE ) < 0 )
		{
			common->Warning( "Couldn't switch to fullscreen mode, reason: %s!", SDL_GetError() );
			return false;
		}
	}
	return true;
}
开发者ID:OpenTechEngine,项目名称:OpenTechBFG,代码行数:34,代码来源:sdl_glimp.cpp

示例14: initWindow

 void Game::initWindow()
 {
     if (config_->fullscreen) {
         SDL_DisplayMode mode;
         if (SDL_GetCurrentDisplayMode(0, &mode) == -1) {
             std::stringstream message;
             message << "Failed to get fullscreen display mode: "
                     << SDL_GetError();
             throw Error(message.str());
         }
         windowWidth_ = mode.w;
         windowHeight_ = mode.h;
     }
     Uint32 flags = SDL_WINDOW_OPENGL;
     if (config_->fullscreen) {
         flags |= SDL_WINDOW_FULLSCREEN;
     }
     window_ = SDL_CreateWindow("Crust", SDL_WINDOWPOS_CENTERED, 
                                SDL_WINDOWPOS_CENTERED, windowWidth_,
                                windowHeight_, flags);
     if (window_ == 0) {
         std::stringstream message;
         message << "Failed to create window: " << SDL_GetError();
         throw Error(message.str());
     }
     if (config_->fullscreen) {
         SDL_GetWindowSize(window_, &windowWidth_, &windowHeight_);
     }
 }
开发者ID:elemel,项目名称:crust,代码行数:29,代码来源:game.cpp

示例15: SDL_COMPAT_GetBitsPerPixel

int SDL_COMPAT_GetBitsPerPixel(void)
{
  int bpp;
  SDL_DisplayMode mode;
  SDL_GetCurrentDisplayMode(0, &mode);
  bpp = SDL_BITSPERPIXEL(mode.format);
  return (bpp==24)? 32 : bpp;
}
开发者ID:Blonder,项目名称:oricutron,代码行数:8,代码来源:system_sdl.c


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