Exemplo n.º 1
0
void video_start_window( )
{
	if ( SDL_VideoInit(video_options.driver) ) {
		fatal( "%s", SDL_GetError() );
	}
	video_window = SDL_CreateWindow(
		video_options.title,
		video_options.position.x,
		video_options.position.y,
		video_options.size.w,
		video_options.size.h,
		SDL_WINDOW_SHOWN | SDL_WINDOW_ALLOW_HIGHDPI );
	if ( video_window == NULL ) {
		fatal( "%s", SDL_GetError() );
	}
	video_renderer = SDL_CreateRenderer( video_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC );
	if ( video_renderer == NULL ) {
		fatal( "%s", SDL_GetError() );
	}
	SDL_SetRenderDrawBlendMode( video_renderer, SDL_BLENDMODE_BLEND );
	SDL_SetHint( SDL_HINT_RENDER_SCALE_QUALITY, "1" );
	SDL_RenderSetLogicalSize(
		video_renderer,
		video_options.logical_size.w,
		video_options.logical_size.h );
	SDL_SetWindowGrab( video_window, video_options.grab_input );
	if ( video_options.set_mode ) {
		SDL_SetWindowDisplayMode( video_window, &video_options.mode );
	} else {
		SDL_SetWindowDisplayMode( video_window, NULL );
	}
	SDL_SetWindowFullscreen( video_window, video_options.fullscreen );
}
Exemplo n.º 2
0
void GraphicsManager::setScreenSize(int width, int height) {
	// Force calling it from the main thread
	if (!Common::isMainThread()) {
		Events::MainThreadFunctor<void> functor(boost::bind(&GraphicsManager::setScreenSize, this, width, height));

		return RequestMan.callInMainThread(functor);
	}

	// Save properties
	// uint32 flags     = SDL_GetWindowFlags(_screen);

	destroyContext();

	SDL_DisplayMode displayMode;
	// Now try to change modes
	if (!_fullScreen) {
		SDL_SetWindowSize(_screen, width, height);
	} else {
		SDL_SetWindowFullscreen(_screen, 0);
		displayMode.w = width;
		displayMode.h = height;
		displayMode.driverdata = 0;
		displayMode.refresh_rate = 0;
		displayMode.format = 0;
		SDL_SetWindowDisplayMode(_screen, &displayMode);
		SDL_SetWindowFullscreen(_screen, SDL_WINDOW_FULLSCREEN);
	}

	if (!_screen) {
		// Could not change mode, revert back.
		if (!_fullScreen)
			SDL_SetWindowSize(_screen, _width, _height);
		else {
			displayMode.w = _width;
			displayMode.h = _height;
			SDL_SetWindowDisplayMode(_screen,  &displayMode);
		}

		// There's no reason how this could possibly fail, but ok...
		if (!_screen)
			throw Common::Exception("Failed changing the resolution and then failed reverting.");

		return;
	}

	_width = width;
	_height = height;
	rebuildContext();

	// Let the NotificationManager notify the Notifyables that the resolution changed
		NotificationMan.resized(_width, _height, width, height);

}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
int     	GLimp_SetMode( int *pwidth, int *pheight, int mode, qboolean fullscreen )
{
	int width;
	int height;

	if ( !ri.Vid_GetModeInfo( &width, &height, mode ) )
	{
		ri.Con_Printf( PRINT_ALL, " invalid mode\n" );
		return rserr_invalid_mode;
	}

	if (fullscreen)
	{
		SDL_DisplayMode mode = { 0 };
		mode.w = width;
		mode.h = height;

		SDL_SetWindowDisplayMode(window, &mode);
		SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN);
	}
	else
	{
		SDL_SetWindowFullscreen(window, 0);
		SDL_SetWindowSize(window, width, height);
	}

	*pwidth = width;
	*pheight = height;
	
	// let the sound and input subsystems know about the new window
	ri.Vid_NewWindow (width, height);

	return rserr_ok;
}
Exemplo n.º 5
0
void fs_ml_toggle_fullscreen() {
    fs_log("fs_ml_toggle_fullscreen\n");
#ifdef USE_SDL2
    if (g_fs_emu_video_fullscreen_mode == FULLSCREEN_WINDOW) {
        fs_emu_warning("Cannot toggle fullscreen with fullscreen-mode=window");
        return;
    }

    int display_index = 0;
    SDL_DisplayMode mode;
    memset(&mode, 0, sizeof(SDL_DisplayMode));
    if (SDL_GetDesktopDisplayMode(display_index, &mode) == 0) {
        SDL_SetWindowDisplayMode(g_fs_ml_window, &mode);
    }

    g_fs_emu_video_fullscreen = !g_fs_emu_video_fullscreen;
    int flags = 0;
    if (g_fs_emu_video_fullscreen) {
        if (g_fs_emu_video_fullscreen_mode == FULLSCREEN_DESKTOP) {
            flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
        }
        else {
            flags = SDL_WINDOW_FULLSCREEN;
        }
    }
    SDL_SetWindowFullscreen(g_fs_ml_window, flags);

#else
    g_fs_emu_video_fullscreen = !g_fs_emu_video_fullscreen;
    destroy_opengl_state();
    set_video_mode();
    recreate_opengl_state();
#endif
}
Exemplo n.º 6
0
bool Client::SetResolution (const int w, const int h)
{
    SDL_DisplayMode mode;

    SDL_SetWindowSize (mainWindow, w, h);

    if (SDL_GetWindowDisplayMode (mainWindow, &mode) < 0)
    {
        SetError ("Error getting display mode: %s", SDL_GetError ());
        return false;
    }

    mode.w = w;
    mode.h = h;

    if (SDL_SetWindowDisplayMode (mainWindow, &mode) < 0)
    {
        SetError ("Error setting display to %d x %d %s", w, h, SDL_GetError ());
        return false;
    }

    if (fullscreen) //  need to switch to windowed to take effect
    {
        if (!SetFullScreen (false))
            return false;

        if (!SetFullScreen (true))
            return false;
    }

    SaveSetting (settingsPath.c_str (), SCREENWIDTH_SETTING, w);
    SaveSetting (settingsPath.c_str (), SCREENHEIGHT_SETTING, h);

    return true;
}
Exemplo n.º 7
0
void SDL2Window::changeMode(DisplayMode mode, bool makeFullscreen) {
	
	if(!m_window) {
		m_size = mode.resolution;
		m_fullscreen = makeFullscreen;
		return;
	}
	
	if(m_fullscreen == makeFullscreen && m_size == mode.resolution) {
		return;
	}
	
	bool wasFullscreen = m_fullscreen;
	
	m_renderer->beforeResize(wasFullscreen || makeFullscreen);
	
	if(makeFullscreen) {
		if(mode.resolution != Vec2i_ZERO) {
			SDL_DisplayMode sdlmode;
			SDL_DisplayMode requested;
			requested.driverdata = NULL;
			requested.format = 0;
			requested.refresh_rate = 0;
			requested.w = mode.resolution.x;
			requested.h = mode.resolution.y;
			int display = SDL_GetWindowDisplayIndex(m_window);
			if(!SDL_GetClosestDisplayMode(display, &requested, &sdlmode)) {
				if(SDL_GetDesktopDisplayMode(display, &sdlmode)) {
					return;
				}
			}
			if(SDL_SetWindowDisplayMode(m_window, &sdlmode) < 0) {
				return;
			}
		}
	}
	
	Uint32 flags = getSDLFlagsForMode(mode.resolution, makeFullscreen);
	if(SDL_SetWindowFullscreen(m_window, flags) < 0) {
		return;
	}
	
	if(!makeFullscreen) {
		SDL_SetWindowSize(m_window, mode.resolution.x, mode.resolution.y);
	}
	
	if(wasFullscreen != makeFullscreen) {
		onToggleFullscreen(makeFullscreen);
	}
	
	if(makeFullscreen) {
		// SDL regrettably sends resize events when a fullscreen window is minimized.
		// Because of that we ignore all size change events when fullscreen.
		// Instead, handle the size change here.
		updateSize();
	}
	
	tick();
}
Exemplo n.º 8
0
void video_set_mode( const struct video_mode *mode )
{
	video_options.mode = *(SDL_DisplayMode*)mode;
	video_options.set_mode = 1;
	if ( video_window != NULL ) {
		SDL_SetWindowDisplayMode( video_window, &video_options.mode );
	}
}
Exemplo n.º 9
0
bool Window::fullscreen()
{
    SDL_DisplayMode dm;
    SDL_GetDesktopDisplayMode(0, &dm);
    SDL_SetWindowDisplayMode(window, &dm);
    SDL_SetWindowFullscreen(window, !(SDL_GetWindowFlags(window)&SDL_WINDOW_FULLSCREEN));
    return true;
}
Exemplo n.º 10
0
	int inline Window::setWindowDisplayMode(State & state, SDL_Window  * window){
		Stack * stack = state.stack;
		DisplayMode * interfaceDisplayMode = state.getInterface<DisplayMode>("LuaSDL_DisplayMode");
		SDL_DisplayMode * displayMode = interfaceDisplayMode->get(1);
		if (displayMode){
			SDL_SetWindowDisplayMode(window, displayMode);
		}
		return 0;
	}
Exemplo n.º 11
0
	int Window::setDisplayMode(State & state, SDL_Window  * window){
		DisplayMode * interfaceDisplayMode = state.getInterface<DisplayMode>("LuaSDL_DisplayMode");
		Stack * stack = state.stack;
		stack->push<bool>(
			SDL_SetWindowDisplayMode(
			window,
			interfaceDisplayMode->get(1)
			) == 0);
		return 1;
	}
Exemplo n.º 12
0
void
GLVideoSystem::apply_video_mode()
{
  if (!g_config->use_fullscreen)
  {
    SDL_SetWindowFullscreen(m_window, 0);
  }
  else
  {
    if (g_config->fullscreen_size.width == 0 &&
        g_config->fullscreen_size.height == 0)
    {
      if (SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN_DESKTOP) != 0)
      {
        log_warning << "failed to switch to desktop fullscreen mode: "
                    << SDL_GetError() << std::endl;
      }
      else
      {
        log_info << "switched to desktop fullscreen mode" << std::endl;
      }
    }
    else
    {
      SDL_DisplayMode mode;
      mode.format = SDL_PIXELFORMAT_RGB888;
      mode.w = g_config->fullscreen_size.width;
      mode.h = g_config->fullscreen_size.height;
      mode.refresh_rate = g_config->fullscreen_refresh_rate;
      mode.driverdata = nullptr;

      if (SDL_SetWindowDisplayMode(m_window, &mode) != 0)
      {
        log_warning << "failed to set display mode: "
                    << mode.w << "x" << mode.h << "@" << mode.refresh_rate << ": "
                    << SDL_GetError() << std::endl;
      }
      else
      {
        if (SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN) != 0)
        {
          log_warning << "failed to switch to fullscreen mode: "
                      << mode.w << "x" << mode.h << "@" << mode.refresh_rate << ": "
                      << SDL_GetError() << std::endl;
        }
        else
        {
          log_info << "switched to fullscreen mode: "
                   << mode.w << "x" << mode.h << "@" << mode.refresh_rate << std::endl;
        }
      }
    }
  }
}
Exemplo n.º 13
0
void sdl_window_info::complete_destroy()
{
	if (fullscreen() && video_config.switchres)
	{
		SDL_SetWindowFullscreen(platform_window<SDL_Window*>(), 0);    // Try to set mode
		SDL_SetWindowDisplayMode(platform_window<SDL_Window*>(), &m_original_mode->mode);    // Try to set mode
		SDL_SetWindowFullscreen(platform_window<SDL_Window*>(), SDL_WINDOW_FULLSCREEN);    // Try to set mode
	}
	SDL_DestroyWindow(platform_window<SDL_Window*>());
	// release all keys ...
	downcast<sdl_osd_interface &>(machine().osd()).release_keys();
}
Exemplo n.º 14
0
void ToggleFullscreen(photon_window &window){
    window.fullscreen = !window.fullscreen;

    if(window.fullscreen){
        SDL_DisplayMode mode;
        SDL_GetDesktopDisplayMode(0, &mode);
        SDL_SetWindowDisplayMode(window.window_SDL, &mode);
    }
    SDL_SetWindowFullscreen(window.window_SDL, SDL_bool(window.fullscreen));

    PrintToLog("INFO: Window toggled fullscreen.");
}
Exemplo n.º 15
0
	void ProcessEvent(OpenBlox::OBGame* gameInst, SDL_Event event){
		switch(event.type){
			case SDL_MOUSEMOTION: {
				SDL_MouseMotionEvent motion = event.motion;
				gameInst->mouseMove(QPoint(motion.x, motion.y));
				break;
			}
			case SDL_MOUSEBUTTONDOWN: {
				SDL_MouseButtonEvent btn = event.button;
				gameInst->mousePress(btn.button, QPoint(btn.x, btn.y));
				break;
			}
			case SDL_KEYDOWN: {
				SDL_KeyboardEvent keyEvt = event.key;
				SDL_Keysym key = keyEvt.keysym;

				#ifndef OPENBLOX_STUDIO
				if(key.sym == SDLK_F11){
					if((SDL_GetWindowFlags(OpenBlox::mw) & SDL_WINDOW_FULLSCREEN) == SDL_WINDOW_FULLSCREEN){
						SDL_SetWindowFullscreen(OpenBlox::mw, 0);
					}else{
						SDL_DisplayMode dm;
						if(SDL_GetDesktopDisplayMode(SDL_GetWindowDisplayIndex(OpenBlox::mw), &dm) == 0){
							SDL_SetWindowDisplayMode(OpenBlox::mw, &dm);
						}
						SDL_SetWindowFullscreen(OpenBlox::mw, SDL_WINDOW_FULLSCREEN);
					}
				}
				#endif
				break;
			}
			case SDL_KEYUP: {
				SDL_KeyboardEvent keyEvt = event.key;
				SDL_Keysym key = keyEvt.keysym;
				Q_UNUSED(key)
				break;
			}
			case SDL_WINDOWEVENT: {
				SDL_WindowEvent wevt = event.window;
				switch(wevt.event){
					case SDL_WINDOWEVENT_RESIZED: {
						gameInst->resized();
					}
				}
				break;
			}
			case SDL_QUIT: {
				shouldQuit = true;
				break;
			}
		}
	}
Exemplo n.º 16
0
bool Window::setFullscreen(bool fullscreen, Window::FullscreenType fstype)
{
	if (!window)
		return false;

	if (graphics.get() && graphics->isCanvasActive())
		throw love::Exception("love.window.setFullscreen cannot be called while a Canvas is active in love.graphics.");

	WindowSettings newsettings = settings;
	newsettings.fullscreen = fullscreen;
	newsettings.fstype = fstype;

	Uint32 sdlflags = 0;

	if (fullscreen)
	{
		if (fstype == FULLSCREEN_DESKTOP)
			sdlflags = SDL_WINDOW_FULLSCREEN_DESKTOP;
		else
		{
			sdlflags = SDL_WINDOW_FULLSCREEN;

			SDL_DisplayMode mode = {};
			mode.w = windowWidth;
			mode.h = windowHeight;

			SDL_GetClosestDisplayMode(SDL_GetWindowDisplayIndex(window), &mode, &mode);
			SDL_SetWindowDisplayMode(window, &mode);
		}
	}

#ifdef LOVE_ANDROID
	love::android::setImmersive(fullscreen);
#endif

	if (SDL_SetWindowFullscreen(window, sdlflags) == 0)
	{
		SDL_GL_MakeCurrent(window, context);
		updateSettings(newsettings, true);

		// Apparently this gets un-set when we exit fullscreen (at least in OS X).
		if (!fullscreen)
			SDL_SetWindowMinimumSize(window, settings.minwidth, settings.minheight);

		return true;
	}

	return false;
}
Exemplo n.º 17
0
GHOST_IWindow *GHOST_SystemSDL::createWindow(const STR_String &title,
                                             GHOST_TInt32 left,
                                             GHOST_TInt32 top,
                                             GHOST_TUns32 width,
                                             GHOST_TUns32 height,
                                             GHOST_TWindowState state,
                                             GHOST_TDrawingContextType type,
                                             GHOST_GLSettings glSettings,
                                             const bool exclusive,
                                             const GHOST_TEmbedderWindowID parentWindow)
{
  GHOST_WindowSDL *window = NULL;

  window = new GHOST_WindowSDL(this,
                               title,
                               left,
                               top,
                               width,
                               height,
                               state,
                               parentWindow,
                               type,
                               ((glSettings.flags & GHOST_glStereoVisual) != 0),
                               exclusive);

  if (window) {
    if (GHOST_kWindowStateFullScreen == state) {
      SDL_Window *sdl_win = window->getSDLWindow();
      SDL_DisplayMode mode;

      static_cast<GHOST_DisplayManagerSDL *>(m_displayManager)->getCurrentDisplayModeSDL(mode);

      SDL_SetWindowDisplayMode(sdl_win, &mode);
      SDL_ShowWindow(sdl_win);
      SDL_SetWindowFullscreen(sdl_win, SDL_TRUE);
    }

    if (window->getValid()) {
      m_windowManager->addWindow(window);
      pushEvent(new GHOST_Event(getMilliSeconds(), GHOST_kEventWindowSize, window));
    }
    else {
      delete window;
      window = NULL;
    }
  }
  return window;
}
Exemplo n.º 18
0
void Display::SetResolution(const int w, const int h, bool fullScreen) {
    resizing = true;
    SDL_DisplayMode displayMode;
    int getMode = SDL_GetCurrentDisplayMode(0, &displayMode);

    if(getMode != 0) {
        std::cerr << "failed to get display mode" << std::endl;
    }

    this->width = w;
    this->height = h;

    SDL_SetWindowSize(_window, this->width, this->height);
    displayMode.w = w;
    displayMode.h = h;
    SDL_SetWindowDisplayMode(_window, &displayMode);
    SDL_GL_MakeCurrent(_window, _context);

    glViewport(0, 0, this->width, this->height);
    resizing = false;
}
Exemplo n.º 19
0
    void VideoWrapper::setVideoMode(int width, int height, bool fullscreen, bool windowBorder)
    {
        SDL_SetWindowFullscreen(mWindow, 0);

        if (SDL_GetWindowFlags(mWindow) & SDL_WINDOW_MAXIMIZED)
            SDL_RestoreWindow(mWindow);

        if (fullscreen)
        {
            SDL_DisplayMode mode;
            SDL_GetWindowDisplayMode(mWindow, &mode);
            mode.w = width;
            mode.h = height;
            SDL_SetWindowDisplayMode(mWindow, &mode);
            SDL_SetWindowFullscreen(mWindow, fullscreen);
        }
        else
        {
            SDL_SetWindowSize(mWindow, width, height);
            SDL_SetWindowBordered(mWindow, windowBorder ? SDL_TRUE : SDL_FALSE);
        }
    }
Exemplo n.º 20
0
void sdl_window_info::toggle_full_screen()
{
	// if we are in debug mode, never go full screen
	if (machine().debug_flags & DEBUG_FLAG_OSD_ENABLED)
		return;

	// If we are going fullscreen (leaving windowed) remember our windowed size
	if (!fullscreen())
	{
		m_windowed_dim = get_size();
	}

	// reset UI to main menu
	machine().ui().menu_reset();
	// kill off the drawers
	renderer_reset();
	bool is_osx = false;
#ifdef SDLMAME_MACOSX
	// FIXME: This is weird behaviour and certainly a bug in SDL
	is_osx = true;
#endif
	if (fullscreen() && (video_config.switchres || is_osx))
	{
		SDL_SetWindowFullscreen(platform_window(), 0);    // Try to set mode
		SDL_SetWindowDisplayMode(platform_window(), &m_original_mode->mode);    // Try to set mode
		SDL_SetWindowFullscreen(platform_window(), SDL_WINDOW_FULLSCREEN);    // Try to set mode
	}
	SDL_DestroyWindow(platform_window());
	set_platform_window(nullptr);

	downcast<sdl_osd_interface &>(machine().osd()).release_keys();

	set_renderer(osd_renderer::make_for_type(video_config.mode, shared_from_this()));

	// toggle the window mode
	set_fullscreen(!fullscreen());

	complete_create();
}
Exemplo n.º 21
0
void fs_ml_set_fullscreen(bool fullscreen)
{
    if (!is_video_thread()) {
        if (fullscreen) {
            fs_log("Posting enable fullscreen event\n");
            post_video_event(FS_ML_VIDEO_EVENT_ENABLE_FULLSCREEN);
        } else {
            fs_log("Posting disable fullscreen event\n");
            post_video_event(FS_ML_VIDEO_EVENT_DISABLE_FULLSCREEN);
        }
        return;
    }

    if (fullscreen == g_fs_emu_video_fullscreen)
        return;

    if (g_fs_emu_video_fullscreen_mode == FULLSCREEN_WINDOW) {
        fs_emu_warning("Cannot toggle fullscreen with fullscreen-mode=window");
        return;
    }

    int display_index = 0;
    SDL_DisplayMode mode;
    memset(&mode, 0, sizeof(SDL_DisplayMode));
    if (SDL_GetDesktopDisplayMode(display_index, &mode) == 0) {
        SDL_SetWindowDisplayMode(g_fs_ml_window, &mode);
    }

    int flags = 0;
    if (fullscreen) {
        if (g_fs_emu_video_fullscreen_mode == FULLSCREEN_DESKTOP)
            flags = SDL_WINDOW_FULLSCREEN_DESKTOP;
        else
            flags = SDL_WINDOW_FULLSCREEN;
    }
    SDL_SetWindowFullscreen(g_fs_ml_window, flags);
    g_fs_emu_video_fullscreen = fullscreen;
}
Exemplo n.º 22
0
qboolean VID_CreateWindow( int width, int height, qboolean fullscreen )
{
#ifdef XASH_SDL
	static string	wndname;
	Uint32 wndFlags = SDL_WINDOW_MOUSE_FOCUS | SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE;

	Q_strncpy( wndname, GI->title, sizeof( wndname ));

	host.hWnd = SDL_CreateWindow(wndname, r_xpos->integer,
		r_ypos->integer, width, height, wndFlags);

	if( !host.hWnd )
	{
		MsgDev( D_ERROR, "VID_CreateWindow: couldn't create '%s': %s\n", wndname, SDL_GetError());
		return false;
	}

	if( fullscreen )
	{
		SDL_DisplayMode want, got;

		want.w = width;
		want.h = height;
		want.driverdata = NULL;
		want.format = want.refresh_rate = 0; // don't care

		if( !SDL_GetClosestDisplayMode(0, &want, &got) )
			return false;

		MsgDev(D_NOTE, "Got closest display mode: %ix%i@%i\n", got.w, got.h, got.refresh_rate);

		if( SDL_SetWindowDisplayMode(host.hWnd, &got) == -1 )
			return false;

		if( SDL_SetWindowFullscreen(host.hWnd, SDL_WINDOW_FULLSCREEN) == -1 )
			return false;

	}

	host.window_center_x = width / 2;
	host.window_center_y = height / 2;

#if defined(_WIN32)
	{
		HICON ico;
		SDL_SysWMinfo info;

		if( FS_FileExists( GI->iconpath, true ) )
		{
			char	localPath[MAX_PATH];

			Q_snprintf( localPath, sizeof( localPath ), "%s/%s", GI->gamedir, GI->iconpath );
			ico = LoadImage( NULL, localPath, IMAGE_ICON, 0, 0, LR_LOADFROMFILE|LR_DEFAULTSIZE );

			if( !ico )
			{
				MsgDev( D_INFO, "Extract %s from pak if you want to see it.\n", GI->iconpath );
				ico = LoadIcon( host.hInst, MAKEINTRESOURCE( 101 ) );
			}
		}
		else ico = LoadIcon( host.hInst, MAKEINTRESOURCE( 101 ) );

		if( SDL_GetWindowWMInfo( host.hWnd, &info ) )
		{
			// info.info.info.info.info... Holy shit, SDL?
			SetClassLong( info.info.win.window, GCL_HICON, ico );
		}
	}
#endif

	SDL_ShowWindow( host.hWnd );
#else
	host.hWnd = 1; //fake window
	host.window_center_x = width / 2;
	host.window_center_y = height / 2;
#endif
	if( !glw_state.initialized )
	{
		if( !GL_CreateContext( ))
			return false;

		VID_StartupGamma();
	}
	else
	{
		if( !GL_UpdateContext( ))
			return false;		
	}
	return true;
}
Exemplo n.º 23
0
rserr_t R_ChangeDisplaySettings( int width, int height, qboolean fullscreen )
{
#ifdef XASH_SDL
	SDL_DisplayMode displayMode;

	SDL_GetCurrentDisplayMode(0, &displayMode);

	R_SaveVideoMode( width, height );

	// check our desktop attributes
	glw_state.desktopBitsPixel = SDL_BITSPERPIXEL(displayMode.format);
	glw_state.desktopWidth = displayMode.w;
	glw_state.desktopHeight = displayMode.h;

	glState.fullScreen = fullscreen;

	// check for 4:3 or 5:4
	if( width * 3 != height * 4 && width * 4 != height * 5 )
		glState.wideScreen = true;
	else glState.wideScreen = false;


	if(!host.hWnd)
	{
		if( !VID_CreateWindow( width, height, fullscreen ) )
			return rserr_invalid_mode;
	}
	else if( fullscreen )
	{
		SDL_DisplayMode want, got;

		want.w = width;
		want.h = height;
		want.driverdata = NULL;
		want.format = want.refresh_rate = 0; // don't care

		if( !SDL_GetClosestDisplayMode(0, &want, &got) )
			return rserr_invalid_mode;

		MsgDev(D_NOTE, "Got closest display mode: %ix%i@%i\n", got.w, got.h, got.refresh_rate);

		if( ( SDL_GetWindowFlags(host.hWnd) & SDL_WINDOW_FULLSCREEN ) == SDL_WINDOW_FULLSCREEN)
			if( SDL_SetWindowFullscreen(host.hWnd, 0) == -1 )
				return rserr_invalid_fullscreen;

		if( SDL_SetWindowDisplayMode(host.hWnd, &got) )
			return rserr_invalid_mode;

		if( SDL_SetWindowFullscreen(host.hWnd, SDL_WINDOW_FULLSCREEN) == -1 )
			return rserr_invalid_fullscreen;

		R_ChangeDisplaySettingsFast( got.w, got.h );
	}
	else
	{
		if( SDL_SetWindowFullscreen(host.hWnd, 0) )
			return rserr_invalid_fullscreen;
		SDL_SetWindowSize(host.hWnd, width, height);
		R_ChangeDisplaySettingsFast( width, height );
	}
#endif // XASH_SDL
	return rserr_ok;
}
Exemplo n.º 24
0
/*
===============
GLimp_SetMode
===============
*/
static rserr_t GLimp_SetMode(glconfig_t *glConfig, const windowDesc_t *windowDesc, const char *windowTitle, int mode, qboolean fullscreen, qboolean noborder)
{
	int perChannelColorBits;
	int colorBits, depthBits, stencilBits;
	int samples;
	int i = 0;
	SDL_Surface *icon = NULL;
	Uint32 flags = SDL_WINDOW_SHOWN;
	SDL_DisplayMode desktopMode;
	int display = 0;
	int x = SDL_WINDOWPOS_UNDEFINED, y = SDL_WINDOWPOS_UNDEFINED;

	if ( windowDesc->api == GRAPHICS_API_OPENGL )
	{
		flags |= SDL_WINDOW_OPENGL;
	}

	Com_Printf( "Initializing display\n");

	icon = SDL_CreateRGBSurfaceFrom(
		(void *)CLIENT_WINDOW_ICON.pixel_data,
		CLIENT_WINDOW_ICON.width,
		CLIENT_WINDOW_ICON.height,
		CLIENT_WINDOW_ICON.bytes_per_pixel * 8,
		CLIENT_WINDOW_ICON.bytes_per_pixel * CLIENT_WINDOW_ICON.width,
#ifdef Q3_LITTLE_ENDIAN
		0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
#else
		0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
#endif
		);

	// If a window exists, note its display index
	if( screen != NULL )
		display = SDL_GetWindowDisplayIndex( screen );

	if( SDL_GetDesktopDisplayMode( display, &desktopMode ) == 0 )
	{
		displayAspect = (float)desktopMode.w / (float)desktopMode.h;

		Com_Printf( "Display aspect: %.3f\n", displayAspect );
	}
	else
	{
		Com_Memset( &desktopMode, 0, sizeof( SDL_DisplayMode ) );

		Com_Printf( "Cannot determine display aspect, assuming 1.333\n" );
	}

	Com_Printf( "...setting mode %d:", mode );

	if (mode == -2)
	{
		// use desktop video resolution
		if( desktopMode.h > 0 )
		{
			glConfig->vidWidth = desktopMode.w;
			glConfig->vidHeight = desktopMode.h;
		}
		else
		{
			glConfig->vidWidth = 640;
			glConfig->vidHeight = 480;
			Com_Printf( "Cannot determine display resolution, assuming 640x480\n" );
		}

		//glConfig.windowAspect = (float)glConfig.vidWidth / (float)glConfig.vidHeight;
	}
	else if ( !R_GetModeInfo( &glConfig->vidWidth, &glConfig->vidHeight, /*&glConfig.windowAspect,*/ mode ) )
	{
		Com_Printf( " invalid mode\n" );
		SDL_FreeSurface( icon );
		return RSERR_INVALID_MODE;
	}
	Com_Printf( " %d %d\n", glConfig->vidWidth, glConfig->vidHeight);

	// Center window
	if( r_centerWindow->integer && !fullscreen )
	{
		x = ( desktopMode.w / 2 ) - ( glConfig->vidWidth / 2 );
		y = ( desktopMode.h / 2 ) - ( glConfig->vidHeight / 2 );
	}

	// Destroy existing state if it exists
	if( opengl_context != NULL )
	{
		SDL_GL_DeleteContext( opengl_context );
		opengl_context = NULL;
	}

	if( screen != NULL )
	{
		SDL_GetWindowPosition( screen, &x, &y );
		Com_DPrintf( "Existing window at %dx%d before being destroyed\n", x, y );
		SDL_DestroyWindow( screen );
		screen = NULL;
	}

	if( fullscreen )
	{
		flags |= SDL_WINDOW_FULLSCREEN;
		glConfig->isFullscreen = qtrue;
	}
	else
	{
		if( noborder )
			flags |= SDL_WINDOW_BORDERLESS;

		glConfig->isFullscreen = qfalse;
	}

	colorBits = r_colorbits->integer;
	if ((!colorBits) || (colorBits >= 32))
		colorBits = 24;

	if (!r_depthbits->integer)
		depthBits = 24;
	else
		depthBits = r_depthbits->integer;

	stencilBits = r_stencilbits->integer;
	samples = r_ext_multisample->integer;

	if ( windowDesc->api == GRAPHICS_API_OPENGL )
	{
		for (i = 0; i < 16; i++)
		{
			int testColorBits, testDepthBits, testStencilBits;

			// 0 - default
			// 1 - minus colorBits
			// 2 - minus depthBits
			// 3 - minus stencil
			if ((i % 4) == 0 && i)
			{
				// one pass, reduce
				switch (i / 4)
				{
					case 2 :
						if (colorBits == 24)
							colorBits = 16;
						break;
					case 1 :
						if (depthBits == 24)
							depthBits = 16;
						else if (depthBits == 16)
							depthBits = 8;
					case 3 :
						if (stencilBits == 24)
							stencilBits = 16;
						else if (stencilBits == 16)
							stencilBits = 8;
				}
			}

			testColorBits = colorBits;
			testDepthBits = depthBits;
			testStencilBits = stencilBits;

			if ((i % 4) == 3)
			{ // reduce colorBits
				if (testColorBits == 24)
					testColorBits = 16;
			}

			if ((i % 4) == 2)
			{ // reduce depthBits
				if (testDepthBits == 24)
					testDepthBits = 16;
				else if (testDepthBits == 16)
					testDepthBits = 8;
			}

			if ((i % 4) == 1)
			{ // reduce stencilBits
				if (testStencilBits == 24)
					testStencilBits = 16;
				else if (testStencilBits == 16)
					testStencilBits = 8;
				else
					testStencilBits = 0;
			}

			if (testColorBits == 24)
				perChannelColorBits = 8;
			else
				perChannelColorBits = 4;

			SDL_GL_SetAttribute( SDL_GL_RED_SIZE, perChannelColorBits );
			SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, perChannelColorBits );
			SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, perChannelColorBits );
			SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, testDepthBits );
			SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, testStencilBits );

			SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, samples ? 1 : 0 );
			SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, samples );

			if ( windowDesc->gl.majorVersion )
			{
				int compactVersion = windowDesc->gl.majorVersion * 100 + windowDesc->gl.minorVersion * 10;

				SDL_GL_SetAttribute( SDL_GL_CONTEXT_MAJOR_VERSION, windowDesc->gl.majorVersion );
				SDL_GL_SetAttribute( SDL_GL_CONTEXT_MINOR_VERSION, windowDesc->gl.minorVersion );

				if ( windowDesc->gl.profile == GLPROFILE_ES || compactVersion >= 320 )
				{
					int profile;
					switch ( windowDesc->gl.profile )
					{
					default:
					case GLPROFILE_COMPATIBILITY:
						profile = SDL_GL_CONTEXT_PROFILE_COMPATIBILITY;
						break;

					case GLPROFILE_CORE:
						profile = SDL_GL_CONTEXT_PROFILE_CORE;
						break;

					case GLPROFILE_ES:
						profile = SDL_GL_CONTEXT_PROFILE_ES;
						break;
					}

					SDL_GL_SetAttribute( SDL_GL_CONTEXT_PROFILE_MASK, profile );
				}
			}

			if ( windowDesc->gl.contextFlags & GLCONTEXT_DEBUG )
			{
				SDL_GL_SetAttribute( SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG );
			}

			if(r_stereo->integer)
			{
				glConfig->stereoEnabled = qtrue;
				SDL_GL_SetAttribute(SDL_GL_STEREO, 1);
			}
			else
			{
				glConfig->stereoEnabled = qfalse;
				SDL_GL_SetAttribute(SDL_GL_STEREO, 0);
			}

			SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );
			SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );

			if( ( screen = SDL_CreateWindow( windowTitle, x, y,
					glConfig->vidWidth, glConfig->vidHeight, flags ) ) == NULL )
			{
				Com_DPrintf( "SDL_CreateWindow failed: %s\n", SDL_GetError( ) );
				continue;
			}

#ifndef MACOS_X
			SDL_SetWindowIcon( screen, icon );
#endif

			if( fullscreen )
			{
				SDL_DisplayMode mode;

				switch( testColorBits )
				{
					case 16: mode.format = SDL_PIXELFORMAT_RGB565; break;
					case 24: mode.format = SDL_PIXELFORMAT_RGB24;  break;
					default: Com_DPrintf( "testColorBits is %d, can't fullscreen\n", testColorBits ); continue;
				}

				mode.w = glConfig->vidWidth;
				mode.h = glConfig->vidHeight;
				mode.refresh_rate = glConfig->displayFrequency = r_displayRefresh->integer;
				mode.driverdata = NULL;

				if( SDL_SetWindowDisplayMode( screen, &mode ) < 0 )
				{
					Com_DPrintf( "SDL_SetWindowDisplayMode failed: %s\n", SDL_GetError( ) );
					continue;
				}
			}

			if( ( opengl_context = SDL_GL_CreateContext( screen ) ) == NULL )
			{
				Com_Printf( "SDL_GL_CreateContext failed: %s\n", SDL_GetError( ) );
				continue;
			}

			SDL_GL_SetSwapInterval( r_swapInterval->integer );

			glConfig->colorBits = testColorBits;
			glConfig->depthBits = testDepthBits;
			glConfig->stencilBits = testStencilBits;

			Com_Printf( "Using %d color bits, %d depth, %d stencil display.\n",
					glConfig->colorBits, glConfig->depthBits, glConfig->stencilBits );
			break;
		}
	}
	else
	{
		// Just create a regular window
		if( ( screen = SDL_CreateWindow( windowTitle, x, y,
				glConfig->vidWidth, glConfig->vidHeight, flags ) ) == NULL )
		{
			Com_DPrintf( "SDL_CreateWindow failed: %s\n", SDL_GetError( ) );
		}
		else
		{
#ifndef MACOS_X
			SDL_SetWindowIcon( screen, icon );
#endif
			if( fullscreen )
			{
				if( SDL_SetWindowDisplayMode( screen, NULL ) < 0 )
				{
					Com_DPrintf( "SDL_SetWindowDisplayMode failed: %s\n", SDL_GetError( ) );
				}
			}
		}
	}

	SDL_FreeSurface( icon );

	if (!GLimp_DetectAvailableModes())
	{
		return RSERR_UNKNOWN;
	}

	return RSERR_OK;
}
Exemplo n.º 25
0
SDL_bool
SDLTest_CommonInit(SDLTest_CommonState * state)
{
    int i, j, m, n, w, h;
    SDL_DisplayMode fullscreen_mode;

    if (state->flags & SDL_INIT_VIDEO) {
        if (state->verbose & VERBOSE_VIDEO) {
            n = SDL_GetNumVideoDrivers();
            if (n == 0) {
                fprintf(stderr, "No built-in video drivers\n");
            } else {
                fprintf(stderr, "Built-in video drivers:");
                for (i = 0; i < n; ++i) {
                    if (i > 0) {
                        fprintf(stderr, ",");
                    }
                    fprintf(stderr, " %s", SDL_GetVideoDriver(i));
                }
                fprintf(stderr, "\n");
            }
        }
        if (SDL_VideoInit(state->videodriver) < 0) {
            fprintf(stderr, "Couldn't initialize video driver: %s\n",
                    SDL_GetError());
            return SDL_FALSE;
        }
        if (state->verbose & VERBOSE_VIDEO) {
            fprintf(stderr, "Video driver: %s\n",
                    SDL_GetCurrentVideoDriver());
        }

        /* Upload GL settings */
        SDL_GL_SetAttribute(SDL_GL_RED_SIZE, state->gl_red_size);
        SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, state->gl_green_size);
        SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, state->gl_blue_size);
        SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, state->gl_alpha_size);
        SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, state->gl_double_buffer);
        SDL_GL_SetAttribute(SDL_GL_BUFFER_SIZE, state->gl_buffer_size);
        SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, state->gl_depth_size);
        SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, state->gl_stencil_size);
        SDL_GL_SetAttribute(SDL_GL_ACCUM_RED_SIZE, state->gl_accum_red_size);
        SDL_GL_SetAttribute(SDL_GL_ACCUM_GREEN_SIZE, state->gl_accum_green_size);
        SDL_GL_SetAttribute(SDL_GL_ACCUM_BLUE_SIZE, state->gl_accum_blue_size);
        SDL_GL_SetAttribute(SDL_GL_ACCUM_ALPHA_SIZE, state->gl_accum_alpha_size);
        SDL_GL_SetAttribute(SDL_GL_STEREO, state->gl_stereo);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, state->gl_multisamplebuffers);
        SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, state->gl_multisamplesamples);
        if (state->gl_accelerated >= 0) {
            SDL_GL_SetAttribute(SDL_GL_ACCELERATED_VISUAL,
                                state->gl_accelerated);
        }
        SDL_GL_SetAttribute(SDL_GL_RETAINED_BACKING, state->gl_retained_backing);
        if (state->gl_major_version) {
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, state->gl_major_version);
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, state->gl_minor_version);
        }
        if (state->gl_debug) {
            SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_DEBUG_FLAG);
        }

        if (state->verbose & VERBOSE_MODES) {
            SDL_Rect bounds;
            SDL_DisplayMode mode;
            int bpp;
            Uint32 Rmask, Gmask, Bmask, Amask;

            n = SDL_GetNumVideoDisplays();
            fprintf(stderr, "Number of displays: %d\n", n);
            for (i = 0; i < n; ++i) {
                fprintf(stderr, "Display %d: %s\n", i, SDL_GetDisplayName(i));

                SDL_zero(bounds);
                SDL_GetDisplayBounds(i, &bounds);
                fprintf(stderr, "Bounds: %dx%d at %d,%d\n", bounds.w, bounds.h, bounds.x, bounds.y);

                SDL_GetDesktopDisplayMode(i, &mode);
                SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask, &Gmask,
                                           &Bmask, &Amask);
                fprintf(stderr,
                        "  Current mode: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
                        mode.w, mode.h, mode.refresh_rate, bpp,
                        SDL_GetPixelFormatName(mode.format));
                if (Rmask || Gmask || Bmask) {
                    fprintf(stderr, "      Red Mask   = 0x%.8x\n", Rmask);
                    fprintf(stderr, "      Green Mask = 0x%.8x\n", Gmask);
                    fprintf(stderr, "      Blue Mask  = 0x%.8x\n", Bmask);
                    if (Amask)
                        fprintf(stderr, "      Alpha Mask = 0x%.8x\n", Amask);
                }

                /* Print available fullscreen video modes */
                m = SDL_GetNumDisplayModes(i);
                if (m == 0) {
                    fprintf(stderr, "No available fullscreen video modes\n");
                } else {
                    fprintf(stderr, "  Fullscreen video modes:\n");
                    for (j = 0; j < m; ++j) {
                        SDL_GetDisplayMode(i, j, &mode);
                        SDL_PixelFormatEnumToMasks(mode.format, &bpp, &Rmask,
                                                   &Gmask, &Bmask, &Amask);
                        fprintf(stderr,
                                "    Mode %d: %dx%d@%dHz, %d bits-per-pixel (%s)\n",
                                j, mode.w, mode.h, mode.refresh_rate, bpp,
                                SDL_GetPixelFormatName(mode.format));
                        if (Rmask || Gmask || Bmask) {
                            fprintf(stderr, "        Red Mask   = 0x%.8x\n",
                                    Rmask);
                            fprintf(stderr, "        Green Mask = 0x%.8x\n",
                                    Gmask);
                            fprintf(stderr, "        Blue Mask  = 0x%.8x\n",
                                    Bmask);
                            if (Amask)
                                fprintf(stderr,
                                        "        Alpha Mask = 0x%.8x\n",
                                        Amask);
                        }
                    }
                }
            }
        }

        if (state->verbose & VERBOSE_RENDER) {
            SDL_RendererInfo info;

            n = SDL_GetNumRenderDrivers();
            if (n == 0) {
                fprintf(stderr, "No built-in render drivers\n");
            } else {
                fprintf(stderr, "Built-in render drivers:\n");
                for (i = 0; i < n; ++i) {
                    SDL_GetRenderDriverInfo(i, &info);
                    SDLTest_PrintRenderer(&info);
                }
            }
        }

        SDL_zero(fullscreen_mode);
        switch (state->depth) {
        case 8:
            fullscreen_mode.format = SDL_PIXELFORMAT_INDEX8;
            break;
        case 15:
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB555;
            break;
        case 16:
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB565;
            break;
        case 24:
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB24;
            break;
        default:
            fullscreen_mode.format = SDL_PIXELFORMAT_RGB888;
            break;
        }
        fullscreen_mode.refresh_rate = state->refresh_rate;

        state->windows =
            (SDL_Window **) SDL_malloc(state->num_windows *
                                        sizeof(*state->windows));
        state->renderers =
            (SDL_Renderer **) SDL_malloc(state->num_windows *
                                        sizeof(*state->renderers));
        if (!state->windows || !state->renderers) {
            fprintf(stderr, "Out of memory!\n");
            return SDL_FALSE;
        }
        for (i = 0; i < state->num_windows; ++i) {
            char title[1024];

            if (state->num_windows > 1) {
                SDL_snprintf(title, SDL_arraysize(title), "%s %d",
                             state->window_title, i + 1);
            } else {
                SDL_strlcpy(title, state->window_title, SDL_arraysize(title));
            }
            state->windows[i] =
                SDL_CreateWindow(title, state->window_x, state->window_y,
                                 state->window_w, state->window_h,
                                 state->window_flags);
            if (!state->windows[i]) {
                fprintf(stderr, "Couldn't create window: %s\n",
                        SDL_GetError());
                return SDL_FALSE;
            }
            if (state->window_minW || state->window_minH) {
                SDL_SetWindowMinimumSize(state->windows[i], state->window_minW, state->window_minH);
            }
            if (state->window_maxW || state->window_maxH) {
                SDL_SetWindowMaximumSize(state->windows[i], state->window_maxW, state->window_maxH);
            }
            SDL_GetWindowSize(state->windows[i], &w, &h);
            if (!(state->window_flags & SDL_WINDOW_RESIZABLE) &&
                (w != state->window_w || h != state->window_h)) {
                printf("Window requested size %dx%d, got %dx%d\n", state->window_w, state->window_h, w, h);
                state->window_w = w;
                state->window_h = h;
            }
            if (SDL_SetWindowDisplayMode(state->windows[i], &fullscreen_mode) < 0) {
                fprintf(stderr, "Can't set up fullscreen display mode: %s\n",
                        SDL_GetError());
                return SDL_FALSE;
            }

            if (state->window_icon) {
                SDL_Surface *icon = SDLTest_LoadIcon(state->window_icon);
                if (icon) {
                    SDL_SetWindowIcon(state->windows[i], icon);
                    SDL_FreeSurface(icon);
                }
            }

            SDL_ShowWindow(state->windows[i]);

            state->renderers[i] = NULL;

            if (!state->skip_renderer
                && (state->renderdriver
                    || !(state->window_flags & SDL_WINDOW_OPENGL))) {
                m = -1;
                if (state->renderdriver) {
                    SDL_RendererInfo info;
                    n = SDL_GetNumRenderDrivers();
                    for (j = 0; j < n; ++j) {
                        SDL_GetRenderDriverInfo(j, &info);
                        if (SDL_strcasecmp(info.name, state->renderdriver) ==
                            0) {
                            m = j;
                            break;
                        }
                    }
                    if (m == n) {
                        fprintf(stderr,
                                "Couldn't find render driver named %s",
                                state->renderdriver);
                        return SDL_FALSE;
                    }
                }
                state->renderers[i] = SDL_CreateRenderer(state->windows[i],
                                            m, state->render_flags);
                if (!state->renderers[i]) {
                    fprintf(stderr, "Couldn't create renderer: %s\n",
                            SDL_GetError());
                    return SDL_FALSE;
                }
                if (state->logical_w && state->logical_h) {
                    SDL_RenderSetLogicalSize(state->renderers[i], state->logical_w, state->logical_h);
                } else if (state->scale) {
                    SDL_RenderSetScale(state->renderers[i], state->scale, state->scale);
                }
                if (state->verbose & VERBOSE_RENDER) {
                    SDL_RendererInfo info;

                    fprintf(stderr, "Current renderer:\n");
                    SDL_GetRendererInfo(state->renderers[i], &info);
                    SDLTest_PrintRenderer(&info);
                }
            }
        }
    }

    if (state->flags & SDL_INIT_AUDIO) {
        if (state->verbose & VERBOSE_AUDIO) {
            n = SDL_GetNumAudioDrivers();
            if (n == 0) {
                fprintf(stderr, "No built-in audio drivers\n");
            } else {
                fprintf(stderr, "Built-in audio drivers:");
                for (i = 0; i < n; ++i) {
                    if (i > 0) {
                        fprintf(stderr, ",");
                    }
                    fprintf(stderr, " %s", SDL_GetAudioDriver(i));
                }
                fprintf(stderr, "\n");
            }
        }
        if (SDL_AudioInit(state->audiodriver) < 0) {
            fprintf(stderr, "Couldn't initialize audio driver: %s\n",
                    SDL_GetError());
            return SDL_FALSE;
        }
        if (state->verbose & VERBOSE_VIDEO) {
            fprintf(stderr, "Audio driver: %s\n",
                    SDL_GetCurrentAudioDriver());
        }

        if (SDL_OpenAudio(&state->audiospec, NULL) < 0) {
            fprintf(stderr, "Couldn't open audio: %s\n", SDL_GetError());
            return SDL_FALSE;
        }
    }

    return SDL_TRUE;
}
Exemplo n.º 26
0
/*
===============
GLimp_SetMode
===============
*/
static int GLimp_SetMode(int mode, bool fullscreen, bool noborder)
{
    const char *glstring;
    int perChannelColorBits;
    int colorBits, depthBits, stencilBits;
    int samples;
    int i = 0;
    SDL_Surface *icon = NULL;
    Uint32 flags = SDL_WINDOW_SHOWN | SDL_WINDOW_OPENGL;
    SDL_DisplayMode desktopMode;
    int display = 0;
    int x = SDL_WINDOWPOS_UNDEFINED, y = SDL_WINDOWPOS_UNDEFINED;

    ri->Printf( PRINT_ALL, "Initializing OpenGL display\n");

    if ( r_allowResize->integer )
        flags |= SDL_WINDOW_RESIZABLE;

#ifdef USE_ICON
    icon = SDL_CreateRGBSurfaceFrom(
               (void *)CLIENT_WINDOW_ICON.pixel_data,
               CLIENT_WINDOW_ICON.width,
               CLIENT_WINDOW_ICON.height,
               CLIENT_WINDOW_ICON.bytes_per_pixel * 8,
               CLIENT_WINDOW_ICON.bytes_per_pixel * CLIENT_WINDOW_ICON.width,
#ifdef Q3_LITTLE_ENDIAN
               0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000
#else
               0xFF000000, 0x00FF0000, 0x0000FF00, 0x000000FF
#endif
           );
#endif

    // If a window exists, note its display index
    if( SDL_window != NULL )
        display = SDL_GetWindowDisplayIndex( SDL_window );

    if( SDL_GetDesktopDisplayMode( display, &desktopMode ) == 0 )
    {
        displayAspect = (float)desktopMode.w / (float)desktopMode.h;

        ri.Printf( PRINT_ALL, "Display aspect: %.3f\n", displayAspect );
    }
    else
    {
        Com_Memset( &desktopMode, 0, sizeof( SDL_DisplayMode ) );

        ri.Printf( PRINT_ALL,
                   "Cannot determine display aspect, assuming 1.333\n" );
    }

    ri->Printf (PRINT_ALL, "...setting mode %d:", mode );

    if (mode == -2)
    {
        // use desktop video resolution
        if( desktopMode.h > 0 )
        {
            glConfig.vidWidth = desktopMode.w;
            glConfig.vidHeight = desktopMode.h;
        }
        else
        {
            glConfig.vidWidth = 640;
            glConfig.vidHeight = 480;
            ri->Printf( PRINT_ALL,
                        "Cannot determine display resolution, assuming 640x480\n" );
        }

        glConfig.windowAspect = (float)glConfig.vidWidth / (float)glConfig.vidHeight;
    }
    else if ( !R_GetModeInfo( &glConfig.vidWidth, &glConfig.vidHeight, &glConfig.windowAspect, mode ) )
    {
        ri->Printf( PRINT_ALL, " invalid mode\n" );
        return RSERR_INVALID_MODE;
    }
    ri->Printf( PRINT_ALL, " %d %d\n", glConfig.vidWidth, glConfig.vidHeight);

    // Center window
    if( r_centerWindow->integer && !fullscreen )
    {
        x = ( desktopMode.w / 2 ) - ( glConfig.vidWidth / 2 );
        y = ( desktopMode.h / 2 ) - ( glConfig.vidHeight / 2 );
    }

    // Destroy existing state if it exists
    if( SDL_glContext != NULL )
    {
        SDL_GL_DeleteContext( SDL_glContext );
        SDL_glContext = NULL;
    }

    if( SDL_window != NULL )
    {
        SDL_GetWindowPosition( SDL_window, &x, &y );
        ri->Printf( PRINT_DEVELOPER, "Existing window at %dx%d before being destroyed\n", x, y );
        SDL_DestroyWindow( SDL_window );
        SDL_window = NULL;
    }

    if( fullscreen )
    {
        flags |= SDL_WINDOW_FULLSCREEN;
        glConfig.isFullscreen = qtrue;
    }
    else
    {
        if( noborder )
            flags |= SDL_WINDOW_BORDERLESS;

        glConfig.isFullscreen = false;
    }

    colorBits = r_colorbits->value;
    if ((!colorBits) || (colorBits >= 32))
        colorBits = 24;

    if (!r_depthbits->value)
        depthBits = 24;
    else
        depthBits = r_depthbits->value;

    stencilBits = r_stencilbits->value;
    samples = r_ext_multisample->value;

    for (i = 0; i < 16; i++)
    {
        int testColorBits, testDepthBits, testStencilBits;

        // 0 - default
        // 1 - minus colorBits
        // 2 - minus depthBits
        // 3 - minus stencil
        if ((i % 4) == 0 && i)
        {
            // one pass, reduce
            switch (i / 4)
            {
            case 2 :
                if (colorBits == 24)
                    colorBits = 16;
                break;
            case 1 :
                if (depthBits == 24)
                    depthBits = 16;
                else if (depthBits == 16)
                    depthBits = 8;
            case 3 :
                if (stencilBits == 24)
                    stencilBits = 16;
                else if (stencilBits == 16)
                    stencilBits = 8;
            }
        }

        testColorBits = colorBits;
        testDepthBits = depthBits;
        testStencilBits = stencilBits;

        if ((i % 4) == 3)
        {   // reduce colorBits
            if (testColorBits == 24)
                testColorBits = 16;
        }

        if ((i % 4) == 2)
        {   // reduce depthBits
            if (testDepthBits == 24)
                testDepthBits = 16;
            else if (testDepthBits == 16)
                testDepthBits = 8;
        }

        if ((i % 4) == 1)
        {   // reduce stencilBits
            if (testStencilBits == 24)
                testStencilBits = 16;
            else if (testStencilBits == 16)
                testStencilBits = 8;
            else
                testStencilBits = 0;
        }

        if (testColorBits == 24)
            perChannelColorBits = 8;
        else
            perChannelColorBits = 4;

#ifdef __sgi /* Fix for SGIs grabbing too many bits of color */
        if (perChannelColorBits == 4)
            perChannelColorBits = 0; /* Use minimum size for 16-bit color */

        /* Need alpha or else SGIs choose 36+ bit RGB mode */
        SDL_GL_SetAttribute( SDL_GL_ALPHA_SIZE, 1);
#endif

        SDL_GL_SetAttribute( SDL_GL_RED_SIZE, perChannelColorBits );
        SDL_GL_SetAttribute( SDL_GL_GREEN_SIZE, perChannelColorBits );
        SDL_GL_SetAttribute( SDL_GL_BLUE_SIZE, perChannelColorBits );
        SDL_GL_SetAttribute( SDL_GL_DEPTH_SIZE, testDepthBits );
        SDL_GL_SetAttribute( SDL_GL_STENCIL_SIZE, testStencilBits );

        SDL_GL_SetAttribute( SDL_GL_MULTISAMPLEBUFFERS, samples ? 1 : 0 );
        SDL_GL_SetAttribute( SDL_GL_MULTISAMPLESAMPLES, samples );

        if(r_stereoEnabled->integer)
        {
            glConfig.stereoEnabled = true;
            SDL_GL_SetAttribute(SDL_GL_STEREO, 1);
        }
        else
        {
            glConfig.stereoEnabled = false;
            SDL_GL_SetAttribute(SDL_GL_STEREO, 0);
        }

        SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 );

#if 0 // if multisampling is enabled on X11, this causes create window to fail.
        // If not allowing software GL, demand accelerated
        if( !r_allowSoftwareGL->integer )
            SDL_GL_SetAttribute( SDL_GL_ACCELERATED_VISUAL, 1 );
#endif

        if( ( SDL_window = SDL_CreateWindow( CLIENT_WINDOW_TITLE, x, y,
                                             glConfig.vidWidth, glConfig.vidHeight, flags ) ) == 0 )
        {
            ri->Printf( PRINT_DEVELOPER, "SDL_CreateWindow failed: %s\n", SDL_GetError( ) );
            continue;
        }

        if( fullscreen )
        {
            SDL_DisplayMode mode;

            switch( testColorBits )
            {
            case 16:
                mode.format = SDL_PIXELFORMAT_RGB565;
                break;
            case 24:
                mode.format = SDL_PIXELFORMAT_RGB24;
                break;
            default:
                ri.Printf( PRINT_DEVELOPER, "testColorBits is %d, can't fullscreen\n", testColorBits );
                continue;
            }

            mode.w = glConfig.vidWidth;
            mode.h = glConfig.vidHeight;
            mode.refresh_rate = glConfig.displayFrequency = ri->Cvar_VariableIntegerValue( "r_displayRefresh" );
            mode.driverdata = NULL;

            if( SDL_SetWindowDisplayMode( SDL_window, &mode ) < 0 )
            {
                ri.Printf( PRINT_DEVELOPER, "SDL_SetWindowDisplayMode failed: %s\n", SDL_GetError( ) );
                continue;
            }
        }

        SDL_SetWindowIcon( SDL_window, icon );

        if( ( SDL_glContext = SDL_GL_CreateContext( SDL_window ) ) == NULL )
        {
            ri->Printf( PRINT_DEVELOPER, "SDL_GL_CreateContext failed: %s\n", SDL_GetError( ) );
            continue;
        }

        SDL_GL_SetSwapInterval( r_swapInterval->integer );

        glConfig.colorBits = testColorBits;
        glConfig.depthBits = testDepthBits;
        glConfig.stencilBits = testStencilBits;

        ri->Printf( PRINT_ALL, "Using %d color bits, %d depth, %d stencil display.\n",
                    glConfig.colorBits, glConfig.depthBits, glConfig.stencilBits );
        break;
    }

    SDL_FreeSurface( icon );

    if( !SDL_window )
    {
        ri->Printf( PRINT_ALL, "Couldn't get a visual\n" );
        return RSERR_INVALID_MODE;
    }

    GLimp_DetectAvailableModes();

    glstring = (char *) qglGetString (GL_RENDERER);
    ri->Printf( PRINT_ALL, "GL_RENDERER: %s\n", glstring );

    return RSERR_OK;
}
Exemplo n.º 27
0
SDL_Window* set_video_mode(int w, int h, int flags)
{
	static SDL_Window* wnd = NULL;
	static SDL_GLContext ctx = NULL;
	static int wnd_flags = 0;

	if(wnd) {
		SDL_DisplayMode mode;
		if(SDL_GetWindowDisplayMode(wnd, &mode) == 0) {
			mode.w = w;
			mode.h = h;
			if(SDL_SetWindowDisplayMode(wnd, &mode) == 0) {
				SDL_SetWindowSize(wnd, w, h);
				SDL_SetWindowFullscreen(wnd, flags&SDL_WINDOW_FULLSCREEN);
				SDL_SetWindowPosition(wnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
				return wnd;
			} else {
				fprintf(stderr, "ERROR: Failed to set window display mode. Destroying window and creating a new one.\n");
			}

		} else {
			fprintf(stderr, "ERROR: Failed to get window display mode. Destroying window and creating a new one.\n");
		}
	}

	wnd_flags = flags;
	
	graphics::texture::unbuild_all();
#if defined(USE_SHADERS) 
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
	SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 1);
	SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
	SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);

	SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
	SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 8);

	if(g_msaa > 0) {
		if(SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS, 1) != 0) {
			std::cerr << "MSAA(" << g_msaa << ") requested but mutlisample buffer couldn't be allocated." << std::endl;
		} else {
			size_t msaa = next_pow2(g_msaa);
			std::cerr << "Requesting MSAA of " << msaa;
			if(SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES, msaa) != 0) {
				std::cerr << " -- Failure, disabled.";
			}
			std::cerr << std::endl;
		}
	}
#endif
	if(global_renderer) {
		SDL_DestroyRenderer(global_renderer);
		global_renderer = NULL;
	}
	if(ctx) {
		SDL_GL_DeleteContext(ctx);
		ctx = NULL;
	}
	if(wnd) {
		SDL_DestroyWindow(wnd);
		global_main_window = wnd = NULL;		
	}
	if(!(flags & CLEANUP_WINDOW_CONTEXT)) {
		global_main_window = wnd = SDL_CreateWindow(module::get_module_pretty_name().c_str(), 
			SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, w, h, flags);
		ctx = SDL_GL_CreateContext(wnd);
		global_renderer = SDL_CreateRenderer(wnd, -1, SDL_RENDERER_ACCELERATED);
#if defined(__GLEW_H__)
	GLenum glew_status = glewInit();
	ASSERT_EQ(glew_status, GLEW_OK);
#endif
		
		reset_opengl_state();
		graphics::texture::rebuild_all();
		texture_frame_buffer::rebuild();
	}
#if defined(USE_SHADERS)
	int depth_size, stencil_size;
	SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &depth_size);
	SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &stencil_size);
	std::cerr << "Depth buffer size: " << depth_size << std::endl;
	std::cerr << "Stenicl buffer size: " << stencil_size << std::endl;
	int depth;
	glGetIntegerv(GL_DEPTH_BITS, &depth);
	std::cerr << "Depth(from GL) buffer size: " << depth << std::endl;

	if(g_msaa > 0 && SDL_GL_GetAttribute(SDL_GL_MULTISAMPLESAMPLES, &g_msaa_set) == 0) {
		std::cerr << "Actual MSAA: " << g_msaa_set << std::endl; 
	}
#endif
	return wnd;
}
Exemplo n.º 28
0
bool CVideoMode::SetVideoMode(int w, int h, int bpp, bool fullscreen)
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
	Uint32 flags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN;
	if (fullscreen)
		flags |= SDL_WINDOW_FULLSCREEN;
	else
		flags |= SDL_WINDOW_RESIZABLE;

	m_Window = SDL_CreateWindow("0 A.D.", 0, 0, w, h, flags);
	if (!m_Window)
	{
		LOGERROR(L"SetVideoMode failed in SDL_CreateWindow: %dx%d:%d %d (\"%hs\")",
			w, h, bpp, fullscreen ? 1 : 0, SDL_GetError());
		return false;
		// TODO: fall back to windowed mode
	}

	if (SDL_SetWindowDisplayMode(m_Window, NULL) < 0)
	{
		LOGERROR(L"SetVideoMode failed in SDL_SetWindowDisplayMode: %dx%d:%d %d (\"%hs\")",
			w, h, bpp, fullscreen ? 1 : 0, SDL_GetError());
		return false;
	}

	SDL_GLContext context = SDL_GL_CreateContext(m_Window);
	if (!context)
	{
		LOGERROR(L"SetVideoMode failed in SDL_GL_CreateContext: %dx%d:%d %d (\"%hs\")",
			w, h, bpp, fullscreen ? 1 : 0, SDL_GetError());
		return false;
	}

	// Grab the current video settings
	SDL_GetWindowSize(m_Window, &m_CurrentW, &m_CurrentH);
	m_CurrentBPP = bpp;

	if (fullscreen)
		SDL_SetWindowGrab(m_Window, SDL_TRUE);
	else
		SDL_SetWindowGrab(m_Window, SDL_FALSE);

#else // SDL 1.2:

	Uint32 flags = SDL_OPENGL;
	if (fullscreen)
		flags |= SDL_FULLSCREEN;
#if !OS_MACOSX
	// TODO: Fix window resizing on OS X, see http://trac.wildfiregames.com/ticket/741
	else
		flags |= SDL_RESIZABLE;
#endif

	SDL_Surface* screen = SDL_SetVideoMode(w, h, bpp, flags);

	if (!screen)
	{
		// If fullscreen fails, try windowed mode
		if (fullscreen)
		{
			LOGWARNING(L"Failed to set the video mode to fullscreen for the chosen resolution "
				L"%dx%d:%d (\"%hs\"), falling back to windowed mode",
				w, h, bpp, SDL_GetError());
			// Using default size for the window for now, as the attempted setting
			// could be as large, or larger than the screen size.
			return SetVideoMode(DEFAULT_WINDOW_W, DEFAULT_WINDOW_H, bpp, false);		
		}
		else
		{
			LOGERROR(L"SetVideoMode failed: %dx%d:%d %d (\"%hs\")",
				w, h, bpp, fullscreen ? 1 : 0, SDL_GetError());
			return false;
		}
	}

	// Grab the current video settings
	m_CurrentW = screen->w;
	m_CurrentH = screen->h;
	m_CurrentBPP = screen->format->BitsPerPixel;

	if (fullscreen)
		SDL_WM_GrabInput(SDL_GRAB_ON);
	else
		SDL_WM_GrabInput(SDL_GRAB_OFF);
#endif

	m_IsFullscreen = fullscreen;

	g_xres = m_CurrentW;
	g_yres = m_CurrentH;

	return true;
}
Exemplo n.º 29
0
static void VID_SDL_Init(void)
{
	int flags;
	int r, g, b, a;
	
	if (glConfig.initialized == true) {
		return;
	}

	flags = SDL_WINDOW_RESIZABLE | SDL_WINDOW_OPENGL | SDL_WINDOW_INPUT_FOCUS | SDL_WINDOW_SHOWN;

#ifdef SDL_WINDOW_ALLOW_HIGHDPI
	flags |= SDL_WINDOW_ALLOW_HIGHDPI;
#endif
	if (r_fullscreen.integer > 0) {
		if (vid_usedesktopres.integer == 1) {
			flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
		}
	} else {
		if (vid_win_borderless.integer > 0) {
			flags |= SDL_WINDOW_BORDERLESS;
		}
	}

#ifdef __APPLE__
	SDL_SetHint(SDL_HINT_VIDEO_MAC_FULLSCREEN_SPACES, "0");
	SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, "0");
#endif

	VID_SDL_InitSubSystem();
	VID_SDL_GL_SetupAttributes();

	VID_SetupModeList();
	VID_SetupResolution();

	if (r_fullscreen.integer == 0) {
		int displayNumber = VID_DisplayNumber(false);
		int xpos = vid_xpos.integer;
		int ypos = vid_ypos.integer;

		VID_AbsolutePositionFromRelative(&xpos, &ypos, &displayNumber);

		sdl_window = SDL_CreateWindow(WINDOW_CLASS_NAME, xpos, ypos, glConfig.vidWidth, glConfig.vidHeight, flags);
	} else {
		int windowWidth = glConfig.vidWidth;
		int windowHeight = glConfig.vidHeight;
		int windowX = SDL_WINDOWPOS_CENTERED;
		int windowY = SDL_WINDOWPOS_CENTERED;
		int displayNumber = VID_DisplayNumber(true);
		SDL_Rect bounds;

		if (SDL_GetDisplayBounds(displayNumber, &bounds) == 0)
		{
			windowX = bounds.x;
			windowY = bounds.y;
			windowWidth = bounds.w;
			windowHeight = bounds.h;
		}
		else
		{
			Com_Printf("Couldn't determine bounds of display #%d, defaulting to main display\n", displayNumber);
		}

		sdl_window = SDL_CreateWindow(WINDOW_CLASS_NAME, windowX, windowY, windowWidth, windowHeight, flags);
	}

	if (r_fullscreen.integer > 0 && vid_usedesktopres.integer != 1) {
		int index;

		index = VID_GetCurrentModeIndex();

		/* FIXME: Make a pre-check if the values render a valid video mode before attempting to switch (when vid_usedesktopres != 1) !! */
		if (index < 0) {
			Com_Printf("Couldn't find a matching video mode for the selected values, check video settings!\n");
		} else {
			if (SDL_SetWindowDisplayMode(sdl_window, &modelist[index]) != 0) {
				Com_Printf("sdl error: %s\n", SDL_GetError());
			}
		}

		if (SDL_SetWindowFullscreen(sdl_window, SDL_WINDOW_FULLSCREEN) < 0) {
			Com_Printf("Failed to change to fullscreen mode\n");
		}
	}
      

	if (VID_SetWindowIcon(sdl_window) < 0) {
		Com_Printf("Failed to set window icon");
	}

	SDL_SetWindowMinimumSize(sdl_window, 320, 240);

	sdl_context = SDL_GL_CreateContext(sdl_window);
	if (!sdl_context) {
		Com_Printf("Couldn't create OpenGL context: %s\n", SDL_GetError());
		return;
	}

	v_gamma.modified = true;
	r_swapInterval.modified = true;
	
	SDL_GL_GetAttribute(SDL_GL_RED_SIZE, &r);
	SDL_GL_GetAttribute(SDL_GL_GREEN_SIZE, &g);
	SDL_GL_GetAttribute(SDL_GL_BLUE_SIZE, &b);
	SDL_GL_GetAttribute(SDL_GL_ALPHA_SIZE, &a);

	glConfig.colorBits = r+g+b+a;
	SDL_GL_GetAttribute(SDL_GL_DEPTH_SIZE, &glConfig.depthBits);
	SDL_GL_GetAttribute(SDL_GL_STENCIL_SIZE, &glConfig.stencilBits);

	glConfig.vendor_string         = glGetString(GL_VENDOR);
	glConfig.renderer_string       = glGetString(GL_RENDERER);
	glConfig.version_string        = glGetString(GL_VERSION);
	glConfig.extensions_string     = glGetString(GL_EXTENSIONS);

	glConfig.initialized = true;
}
Exemplo n.º 30
0
int main(int argc, char** argv)
{
  if(argc != 2){
    printf("usage : %s vidfilename\n", argv[0]);
    return 0;
  }

  /* parse arg */
  filename = argv[1];
  

  /* the window will be resized */
  /* after reading video size */
  winWidth = 640;
  winHeight = 480;

  /************/
  /* init sdl */
  /************/
  if( SDL_Init( SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER ) < 0 ) {
    fprintf( stderr, "Video initialization failed: %s\n", SDL_GetError( ) );
    SDL_Quit( );
    exit(0);
  }

  /* set windows attributes */
  SDL_GetDesktopDisplayMode(0, &desktopMode);
  SDL_SetWindowDisplayMode(screen, &desktopMode); //seems not working ?

  flags = SDL_WINDOW_SHOWN|SDL_WINDOW_RESIZABLE|SDL_WINDOW_OPENGL;

  /* create display */
  screen = SDL_CreateWindow("Waave player",\
			    SDL_WINDOWPOS_UNDEFINED,\
			    SDL_WINDOWPOS_UNDEFINED,\
			    winWidth,\
			    winHeight,\
			    flags);
  
  if( !screen ) {
    fprintf( stderr, "Video mode set failed: %s\n", SDL_GetError( ) );
    SDL_Quit( );
    exit(0);
  }
  
  /**************/
  /* init waave */
  /**************/

  /* start waave and load file */
  WV_waaveInit(WAAVE_INIT_AUDIO|WAAVE_INIT_VIDEO);
  stream = WV_getStream(filename);
  
  /* build a streaming object for the screen */
  int streamType = WV_getStreamType(stream);
  if(streamType == WV_STREAM_TYPE_VIDEO || streamType == WV_STREAM_TYPE_AUDIOVIDEO){
    screenRenderer = SDL_CreateRenderer(screen, -1, SDL_RENDERER_ACCELERATED);
    SDL_RenderClear(screenRenderer);
    destRect.x = SDL_WINDOWPOS_UNDEFINED;
    destRect.y = SDL_WINDOWPOS_UNDEFINED;
    destRect.w = winWidth;
    destRect.h = winHeight;
    streamObj = WV_getStreamRendererObj(screenRenderer,&destRect,50);
    WV_setStreamingMethod(stream, streamObj);
  }

  /* load the stream */
  WV_loadStream(stream);
  
  /* reset window size for video */
  if(streamObj){
    winWidth = streamObj->srcWidth;
    winHeight = streamObj->srcHeight;
    SDL_SetWindowSize(screen, winWidth, winHeight);
    WV_resetStreamRendererOutput(streamObj, screenRenderer, NULL); //!! update the object !!
  }

  /* at start the stream is paused */
  /* so we launch playback */
  WV_playStream(stream);
  
  /*****************/
  /* display loop  */
  /*****************/
  while( 1 ) {
    processEvents( );
  }
  return(0);
}