Пример #1
0
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;
}
Пример #2
0
bool SDL2Window::initializeFramework() {

#if defined(ARX_DEBUG) && defined(SDL_HINT_NO_SIGNAL_HANDLERS)
    // SDL 2.0.4+
    SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
#endif

    const char * minimize = SDL_GetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS);
    if(minimize) {
        if(*minimize == '0') {
            m_minimizeOnFocusLost = AlwaysDisabled;
        } else {
            m_minimizeOnFocusLost = AlwaysEnabled;
        }
    } else {
        m_minimizeOnFocusLost = Enabled;
    }

    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 ARX_PLATFORM != ARX_PLATFORM_WIN32 && ARX_HAVE_SETENV && ARX_HAVE_UNSETENV
    /*
     * We want the X11 WM_CLASS to match the .desktop file and icon name,
     * but SDL does not let us set it directly.
     */
    const char * oldClass = std::getenv("SDL_VIDEO_X11_WMCLASS");
    if(!oldClass) {
        setenv("SDL_VIDEO_X11_WMCLASS", arx_icon_name.c_str(), 1);
    }
    BOOST_SCOPE_EXIT((oldClass)) {
        if(!oldClass) {
            // Don't overrride WM_CLASS for SDL child processes
            unsetenv("SDL_VIDEO_X11_WMCLASS");
        }
    }
    BOOST_SCOPE_EXIT_END
#endif

    if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
        LogError << "Failed to initialize SDL: " << SDL_GetError();
        return false;
    }

    SDL_version ver;
    SDL_GetVersion(&ver);
    std::ostringstream runtimeVersion;
    runtimeVersion << int(ver.major) << '.' << int(ver.minor) << '.' << int(ver.patch);
    LogInfo << "Using SDL " << runtimeVersion.str();
    CrashHandler::setVariable("SDL version (runtime)", runtimeVersion.str());
    credits::setLibraryCredits("windowing", "SDL " + runtimeVersion.str());

#ifdef ARX_DEBUG
    // No SDL, this is more annoying than helpful!
    if(ver.major == 2 && ver.minor == 0 && ver.patch < 4) {
        // Earlier versions don't support SDL_HINT_NO_SIGNAL_HANDLERS
#if defined(SIGINT)
        signal(SIGINT, SIG_DFL);
#endif
#if defined(SIGTERM)
        signal(SIGTERM, SIG_DFL);
#endif
    }
#endif

    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;
}
Пример #3
0
bool SDLWindow::initializeFramework() {
	
	arx_assert_msg(mainWindow == NULL, "SDL only supports one window");
	arx_assert(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_NOPARACHUTE) < 0) {
		LogError << "Failed to initialize SDL: " << SDL_GetError();
		return false;
	}
	
	const SDL_version * ver = SDL_Linked_Version();
	std::ostringstream runtimeVersion;
	runtimeVersion << int(ver->major) << '.' << int(ver->minor) << '.' << int(ver->patch);
	CrashHandler::setVariable("SDL version", runtimeVersion.str());
	LogInfo << "Using SDL " << runtimeVersion.str();
	
	const SDL_VideoInfo * vid = SDL_GetVideoInfo();
	
	desktopMode.resolution.x = vid->current_w;
	desktopMode.resolution.y = vid->current_h;
	desktopMode.depth = vid->vfmt->BitsPerPixel;
	
	u32 flags = SDL_FULLSCREEN | SDL_ANYFORMAT | SDL_OPENGL | SDL_HWSURFACE;
	SDL_Rect ** modes = SDL_ListModes(NULL, flags);
	if(modes == (SDL_Rect **)(-1)) {
		
		// Any mode is supported, add some standard modes.
		
#define ADD_MODE(x, y) \
		if(desktopMode.resolution != Vec2i(x, y)) { \
			displayModes.push_back(DisplayMode(Vec2i(x, y), desktopMode.depth)); \
		}
		
		// 4:3
		ADD_MODE(640, 480) // VGA
		ADD_MODE(800, 600) // SVGA
		ADD_MODE(1024, 768) // XGA
		ADD_MODE(1280, 960) // SXGA-
		ADD_MODE(1600, 1200) // UXGA
		
		// 5:4
		ADD_MODE(1280, 1024) // SXGA
		
		// 16:9
		ADD_MODE(1280, 720) // 720p
		ADD_MODE(1600, 900) // 900p
		ADD_MODE(1920, 1080) // 1080p
		ADD_MODE(2048, 1152) // 2K
		ADD_MODE(4096, 2304) // 4K
		
		// 16:10
		ADD_MODE(1024, 640) // laptops
		ADD_MODE(1280, 800) // WXGA
		ADD_MODE(1440, 900) // WXGA+
		ADD_MODE(1920, 1200) // WUXGA
		
#undef ADD_MODE
		
		displayModes.push_back(desktopMode);
		
	} else if(modes) {
		for(; *modes; modes++) {
			DisplayMode mode(Vec2i((*modes)->w, (*modes)->h), desktopMode.depth);
			displayModes.push_back(mode);
		}
	} else {
		return false;
	}
	
	std::sort(displayModes.begin(), displayModes.end());
	
	mainWindow = this;
	
	return true;
}