Exemple #1
0
/**
 * @return whether window initialization succeeded
 * @param title char* string with window title
 *
 * Initializes the game window
 */
bool SpringApp::InitWindow(const char* title)
{
	unsigned int sdlInitFlags = SDL_INIT_VIDEO | SDL_INIT_TIMER;
#ifdef WIN32
	// the crash reporter should be catching the errors
	sdlInitFlags |= SDL_INIT_NOPARACHUTE;
#endif
	if ((SDL_Init(sdlInitFlags) == -1)) {
		LOG_L(L_FATAL, "Could not initialize SDL: %s", SDL_GetError());
		return false;
	}

	PrintAvailableResolutions();

	WindowManagerHelper::SetCaption(title);

	if (!SetSDLVideoMode()) {
		LOG_L(L_FATAL, "Failed to set SDL video mode: %s", SDL_GetError());
		return false;
	}

	RestoreWindowPosition();
	if (cmdline->IsSet("minimise")) {
		globalRendering->active = false;
		SDL_WM_IconifyWindow();
	}

	glClearColor(0.0f,0.0f,0.0f,0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	SDL_GL_SwapBuffers();

	return true;
}
/**
 * @return whether window initialization succeeded
 * @param title char* string with window title
 *
 * Initializes the game window
 */
bool SpringApp::InitWindow(const char* title)
{
	// SDL will cause a creation of gpu-driver thread that will clone its name from the starting threads (= this one = mainthread)
	Threading::SetThreadName("gpu-driver");

	// the crash reporter should be catching errors, not SDL
	if ((SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) == -1)) {
		LOG_L(L_FATAL, "Could not initialize SDL: %s", SDL_GetError());
		return false;
	}

	PrintAvailableResolutions();
	SDL_DisableScreenSaver();

	if (!CreateSDLWindow(title)) {
		LOG_L(L_FATAL, "Failed to set SDL video mode: %s", SDL_GetError());
		return false;
	}

	if (cmdline->IsSet("minimise")) {
		SDL_HideWindow(window);
	}

	// anyone other thread spawned from the main-process should be `unknown`
	Threading::SetThreadName("unknown");
	return true;
}
void 
Graphics2D::PrintVideoInfo( )
{
    Assert( ::SDL_WasInit( SDL_INIT_VIDEO ) != 0 );

    char driverName[ 50 ] = "";
    char * name = ::SDL_VideoDriverName( driverName, 50 );
    Assert( name );
    cout << "Video driver: " << driverName << endl;

    bool videoModeSet = (m_spScreenSurface != 0);

    const ::SDL_VideoInfo * videoInfo = ::SDL_GetVideoInfo( );
    cout << "Can create hardware surfaces? "
         << (videoInfo->hw_available  ?  "yes"  :  "no") << endl;
    cout << "Window manager available? "
         << (videoInfo->wm_available  ?  "yes"  :  "no") << endl;
    cout << "HW to HW blits accelerated? "
         << (videoInfo->blit_hw  ?  "yes"  :  "no") << endl;
    cout << "HW to HW colorkey blits accelerated? "
         << (videoInfo->blit_hw_CC  ?  "yes"  :  "no") << endl;
    cout << "HW to HW alpha blits accelerated? "
         << (videoInfo->blit_hw_A  ?  "yes"  :  "no") << endl;
    cout << "SW to HW blits accelerated? "
         << (videoInfo->blit_sw  ?  "yes"  :  "no") << endl;
    cout << "SW to HW colorkey blits accelerated? "
         << (videoInfo->blit_sw_CC  ?  "yes"  :  "no") << endl;
    cout << "SW to HW alpha blits accelerated? "
         << (videoInfo->blit_sw_A  ?  "yes"  :  "no") << endl;
    cout << "Color fills accelerated? "
         << (videoInfo->blit_fill  ?  "yes"  :  "no") << endl;
    cout << "Video memory: " << videoInfo->video_mem << endl;

    if ( videoModeSet )
    {
        char * title;
        char * icon;
        ::SDL_WM_GetCaption( &title, &icon );
        if ( title )
            cout << "Window title: \"" << title << "\"" << endl;
        if ( icon )
            cout << "Window icon: \"" << icon << "\"" << endl;
        cout << "Screen surface:" << endl;
        Screen()->PrintInfo( );
    }
    else
    {
        PrintPixelFormat( *(videoInfo->vfmt) );
        cout << "Available resolutions for this pixel format" << endl;
        Uint32 flags = SDL_FULLSCREEN | SDL_HWSURFACE;
        cout << " (SDL_FULLSCREEN | SDL_HWSURFACE):" << endl;
        PrintAvailableResolutions( *(videoInfo->vfmt), flags );
        flags = SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF;
        cout << " (SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF):" << endl;
        PrintAvailableResolutions( *(videoInfo->vfmt), flags );
        flags = SDL_OPENGL;
        cout << " (SDL_OPENGL)" << endl;
        PrintAvailableResolutions( *(videoInfo->vfmt), flags );

        for ( int i = 0; i < NumPixelTypes; ++i )
        {
            ::SDL_PixelFormat format
                    = DetermineSDLPixelFormat( (EPixelType) i );
            cout << "Available resolutions for "
                 << GetPixelTypeName( (EPixelType) i ) << endl;
            flags = SDL_HWSURFACE;
            cout << " (SDL_HWSURFACE):" << endl;
            PrintAvailableResolutions( format, flags );
            flags = SDL_HWSURFACE | SDL_DOUBLEBUF;
            cout << " (SDL_HWSURFACE | SDL_DOUBLEBUF):" << endl;
            PrintAvailableResolutions( format, flags );
            flags = SDL_FULLSCREEN | SDL_HWSURFACE;
            cout << " (SDL_FULLSCREEN | SDL_HWSURFACE):" << endl;
            PrintAvailableResolutions( format, flags );
            flags = SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF;
            cout << " (SDL_FULLSCREEN | SDL_HWSURFACE | SDL_DOUBLEBUF):"
                 << endl;
            PrintAvailableResolutions( format, flags );
            flags = SDL_OPENGL;
            cout << " (SDL_OPENGL)" << endl;
            PrintAvailableResolutions( format, flags );
        }
    }
}