Beispiel #1
0
void UIContext::set_size(const Size2i& dims)
{
  Point2f scale( 1.0f, 1.0f );
  Size2i res(Size2i::zero);

  nom::RocketSDL2RenderInterface* target =
    NOM_DYN_PTR_CAST( nom::RocketSDL2RenderInterface*,
                      Rocket::Core::GetRenderInterface() );
  NOM_ASSERT( target != nullptr );

  const RenderWindow* context = target->window_;
  NOM_ASSERT( context != nullptr );
  if( target && context )
  {
    SDL_RenderGetScale( context->renderer(), &scale.x, &scale.y );
  }

  // Translations for independent resolution scale dimensions (SDL2); this is
  // necessary things like the visual debugger elements to stay on-screen
  // without manually positioning it.
  res.w = dims.w / scale.x;
  res.h = dims.h / scale.y;

  this->context_->SetDimensions( Rocket::Core::Vector2i(res.w, res.h) );
}
Beispiel #2
0
void Window::scaleRenderer()
{
	if (this->_windowMode.w <= 0)
	{
		SDL_SetWindowSize(this->_window, 1, this->_windowMode.h);
	}
	if (this->_windowMode.h <= 0)
	{
		SDL_SetWindowSize(this->_window, this->_windowMode.w, 1);
	}


	SDL_RenderSetLogicalSize(this->_renderer,
		this->_game->settings.getInt("RenderWidth"),
		this->_game->settings.getInt("RenderHeight"));

	// scale the renderer to the smallest window w/h, and to fill up the remaining empty space (assuming the aspect ratio wasn't conserved), increase the rendering resolution of that axis till it fits
	// so the minimum scaled side retains its rendering resolution from settings.xml, but the other side increases its resolution to fit the window
	
	int curWindW;
	int curWindH;

	SDL_GetWindowSize(this->_window, &curWindW, &curWindH);
	
	int tempWinDMin = std::min(curWindW, curWindH);

	int curRendW;
	int curRendH;

	SDL_RenderGetLogicalSize(this->_renderer, &curRendW, &curRendH);

	int tempRendMin = std::min(curRendW, curRendH);

	float aspectMin = static_cast<float>(tempWinDMin) / tempRendMin; // scale on both x and y

	float tempWindMax = std::max(curWindW, curWindH);
	//TODO: possible floating point inaccuracies
	curRendW = (static_cast<int>(curRendW * aspectMin) == tempWinDMin) ? curRendW : tempWindMax / aspectMin;
	curRendW = (static_cast<int>(curRendH * aspectMin) == tempWinDMin) ? curRendH : tempWindMax / aspectMin;

	SDL_RenderSetLogicalSize(this->_renderer, curRendW, curRendH);

	// set scale to be uniform on x and y
	SDL_RenderSetScale(this->_renderer, aspectMin, aspectMin);

	//it's scaled up and we want the min renderer side to remain the same, as it's currently already fitted nicely, but the other side? theres now a blank space, lets increase the rendering resolution of the renderer on that axis

	SDL_RenderGetLogicalSize(this->_renderer, &this->_renderMode.w, &this->_renderMode.h);
	SDL_RenderGetScale(this->_renderer, &this->_renderMode.scaleX, &this->_renderMode.scaleY);
}
Beispiel #3
0
void Renderer::init()
{
    // TODO: android/ios
    // _width = deviceWidth;
    // _height = deviceHeight;
    // Game::getInstance()->engineSettings()->setFullscreen(true);
    // Game::getInstance()->engineSettings()->setScale(1); //or 2, if fullhd device

    std::string message =  "SDL_CreateWindow " + std::to_string(_width) + "x" + std::to_string(_height) + "x" +std::to_string(32)+ " - ";

    uint32_t flags = SDL_WINDOW_SHOWN;
    if (Game::getInstance()->settings()->fullscreen())
    {
        flags |= SDL_WINDOW_FULLSCREEN;
    }

    _sdlWindow = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, _width, _height, flags);
    if (!_sdlWindow)
    {
        throw Exception(message + "[FAIL]");
    }

    Logger::info("RENDERER") << message + "[OK]" << std::endl;

    message =  "SDL_CreateRenderer - ";
    _sdlRenderer = SDL_CreateRenderer(_sdlWindow, -1, SDL_RENDERER_ACCELERATED);
    if (!_sdlRenderer)
    {
        throw Exception(message + "[FAIL]");
    }

    Logger::info("RENDERER") << message + "[OK]" << std::endl;

    SDL_SetRenderDrawBlendMode(_sdlRenderer, SDL_BLENDMODE_BLEND);

    if (Game::getInstance()->settings()->scale() != 0)
    {
        switch (Game::getInstance()->settings()->scale())
        {
            default:
            case 1:
                _width = _width / (_height / 480.0);
                _height= 480;
                break;
            case 2:
                _width = _width / (_height / 960.0);
                _height= 960;
                break;
        }
        SDL_RenderSetLogicalSize(_sdlRenderer, _width, _height);
        SDL_RenderGetScale(_sdlRenderer, &_scaleX, &_scaleY);
    }

    SDL_RendererInfo rendererInfo;
    SDL_GetRendererInfo(_sdlRenderer, &rendererInfo);

    Logger::info("RENDERER") << "name: " << rendererInfo.name << std::endl;
    if (rendererInfo.flags & SDL_RENDERER_SOFTWARE)
    {
        Logger::info("RENDERER") << "flags: SDL_RENDERER_SOFTWARE" << std::endl;
    }
    if (rendererInfo.flags & SDL_RENDERER_ACCELERATED)
    {
        Logger::info("RENDERER") << "flags: SDL_RENDERER_ACCELERATED" << std::endl;
    }
    Logger::info("RENDERER") << "num_texture_formats: " << rendererInfo.num_texture_formats << std::endl;
    for (unsigned int i = 0; i != 16; i++)
    {
        auto& info = Logger::info("RENDERER");
        info << "texture_formats[" << i << "]: ";
        auto format = rendererInfo.texture_formats[i];

        switch (format)
        {
            case SDL_PIXELFORMAT_INDEX1LSB:
                info << "SDL_PIXELFORMAT_INDEX1LSB";
                break;
            case SDL_PIXELFORMAT_INDEX1MSB:
                info << "SDL_PIXELFORMAT_INDEX1MSB";
                break;
            case SDL_PIXELFORMAT_INDEX4LSB:
                info << "SDL_PIXELFORMAT_INDEX4LSB";
                break;
            case SDL_PIXELFORMAT_INDEX4MSB:
                info << "SDL_PIXELFORMAT_INDEX4MSB";
                break;
            case SDL_PIXELFORMAT_INDEX8:
                info << "SDL_PIXELFORMAT_INDEX8";
                break;
            case SDL_PIXELFORMAT_RGBA8888:
                info << "SDL_PIXELFORMAT_RGBA8888";
                break;
            case SDL_PIXELFORMAT_ARGB8888:
                info << "SDL_PIXELFORMAT_ARGB8888";
                break;
            case SDL_PIXELFORMAT_RGB888:
                info << "SDL_PIXELFORMAT_RGB888";
                break;
            default:
                info << format;
                break;
        }
        info << std::endl;
    }
    Logger::info("RENDERER") << "max_texture_width: " << rendererInfo.max_texture_width << std::endl;
    Logger::info("RENDERER") << "max_texture_height: " << rendererInfo.max_texture_height << std::endl;
}
Beispiel #4
0
    Vector2f Renderer::getScale() const {
        Vector2f scale;
        SDL_RenderGetScale(_renderer, &scale.x, &scale.y);

        return scale;
    }