コード例 #1
0
void GuiElement::drawRenderTexture(sf::RenderTexture& texture, sf::RenderTarget& window, sf::Color color, const sf::RenderStates& states)
{
    texture.display();
    
    sf::Sprite sprite(texture.getTexture());
    sprite.setTextureRect(sf::IntRect(0, 0, texture.getSize().x * texture.getView().getViewport().width, texture.getSize().y * texture.getView().getViewport().height));
    sprite.setColor(color);
    sprite.setPosition(rect.left, rect.top);
    sprite.setScale(rect.width / float(texture.getSize().x * texture.getView().getViewport().width), rect.height / float(texture.getSize().y * texture.getView().getViewport().height));
    window.draw(sprite, states);
}
コード例 #2
0
ファイル: Layer.cpp プロジェクト: Violet-CLM/Bunny-Game
void Layer::MakeTexture(sf::RenderTexture& textureImage) const {
	if (WidthPixels == textureImage.getSize().x && HeightPixels == textureImage.getSize().y) { //layer is big enough to support creating a textured background from... if not, the texture will be left fully black
		VertexVector vertices[NUMBEROFTILESETTEXTURES]; //don't reuse Layer::Vertices, in case this layer needs to get drawn soon

		for (int x = 0; x < Width; ++x)
			for (int y = 0; y < Height; ++y)
				DrawTileToVertexArrays(vertices, x,y);

		for (int i = 0; i < NUMBEROFTILESETTEXTURES; ++i)
			if (!vertices[i].empty())
				textureImage.draw(vertices[i].data(), vertices[i].size(), OpenGLPrimitive, LevelPtr->TilesetPtr->TileImages[i]);
	}
	textureImage.display();
}
コード例 #3
0
ファイル: BloomEffect.cpp プロジェクト: lovesonw/plane
void BloomEffect::downsample(const sf::RenderTexture& input, sf::RenderTexture& output)
{
	sf::Shader& downSampler = mShaders.get(Shaders::DownSamplePass);
	downSampler.setParameter("source", input.getTexture());
	downSampler.setParameter("sourceSize", sf::Vector2f(input.getSize()));
	applyShader(downSampler, output);
	output.display();
}
コード例 #4
0
ファイル: PostBloom.cpp プロジェクト: JonnyPtn/xygine
void PostBloom::downSample(const sf::RenderTexture& src, sf::RenderTexture& dst)
{
    auto& shader = m_shaderResource.get(Shader::DownSample);

    shader.setUniform("u_sourceTexture", src.getTexture());
    shader.setUniform("u_sourceSize", sf::Vector2f(src.getSize()));

    applyShader(shader, dst);
    dst.display();
}
コード例 #5
0
ファイル: PostChromeAb.cpp プロジェクト: JonnyPtn/xygine
//public
void PostChromeAb::apply(const sf::RenderTexture& src, sf::RenderTarget& dst)
{
    float windowRatio = static_cast<float>(dst.getSize().y) / static_cast<float>(src.getSize().y);

    m_shader.setUniform("u_sourceTexture", src.getTexture());
    m_shader.setUniform("u_time", accumulatedTime * (10.f * windowRatio));
    m_shader.setUniform("u_lineCount", windowRatio  * scanlineCount);

    applyShader(m_shader, dst);
}
コード例 #6
0
ファイル: PostChromeAb.cpp プロジェクト: JonnyPtn/pseuthe
//public
void PostChromeAb::apply(const sf::RenderTexture& src, sf::RenderTarget& dst)
{
    float windowRatio = static_cast<float>(dst.getSize().y) / static_cast<float>(src.getSize().y);

    auto& shader = m_shaderResource.get(Shader::Type::PostChromeAb);
    shader.setParameter("u_sourceTexture", src.getTexture());
    shader.setParameter("u_time", accumulatedTime * (10.f * windowRatio));
    shader.setParameter("u_lineCount", windowRatio  * scanlineCount);

    applyShader(shader, dst);
}
コード例 #7
0
ファイル: BloomEffect.cpp プロジェクト: lovesonw/plane
void BloomEffect::apply(const sf::RenderTexture& input, sf::RenderTarget& output)
{
	prepareTextures(input.getSize());
	filterBright(input, mBrightnessTexture);
	downsample(mBrightnessTexture, mFirstPassTextures[0]);
	blurMultipass(mFirstPassTextures);
	downsample(mFirstPassTextures[0], mSecondPassTextures[0]);
	blurMultipass(mSecondPassTextures);
	add(mFirstPassTextures[0], mSecondPassTextures[0], mFirstPassTextures[1]);
	mFirstPassTextures[1].display();
	add(input, mFirstPassTextures[1], output);
}
コード例 #8
0
void GuiElement::adjustRenderTexture(sf::RenderTexture& texture)
{
    P<WindowManager> window_manager = engine->getObject("windowManager");
    //Hack the rectangle for this element so it sits perfectly on pixel boundaries.
    sf::Vector2f half_pixel = (window_manager->mapPixelToCoords(sf::Vector2i(1, 1)) - window_manager->mapPixelToCoords(sf::Vector2i(0, 0))) / 2.0f;
    sf::Vector2f top_left = window_manager->mapPixelToCoords(window_manager->mapCoordsToPixel(sf::Vector2f(rect.left, rect.top) + half_pixel));
    sf::Vector2f bottom_right = window_manager->mapPixelToCoords(window_manager->mapCoordsToPixel(sf::Vector2f(rect.left + rect.width, rect.top + rect.height) + half_pixel));
    rect.left = top_left.x;
    rect.top = top_left.y;
    rect.width = bottom_right.x - top_left.x;
    rect.height = bottom_right.y - top_left.y;

    sf::Vector2i texture_size = window_manager->mapCoordsToPixel(sf::Vector2f(rect.width, rect.height) + half_pixel) - window_manager->mapCoordsToPixel(sf::Vector2f(0, 0));
    unsigned int sx = powerOfTwo(texture_size.x);
    unsigned int sy = powerOfTwo(texture_size.y);
    if (texture.getSize().x != sx && texture.getSize().y != sy)
    {
        texture.create(sx, sy, false);
    }
    //Set the view so it covers this elements normal rect. So we can draw exactly the same on this texture as no the normal screen.
    sf::View view(rect);
    view.setViewport(sf::FloatRect(0, 0, float(texture_size.x) / float(sx), float(texture_size.y) / float(sy)));
    texture.setView(view);
}
コード例 #9
0
ファイル: BloomEffect.cpp プロジェクト: chehob/SFMLDev
void BloomEffect::Apply( const sf::RenderTexture& input, sf::RenderTarget& output )
{
	pImpl->PrepareTextures( input.getSize() );

	pImpl->FilterBright( input, pImpl->mBrightnessTexture );

	pImpl->Downsample( pImpl->mBrightnessTexture, pImpl->mFirstPassTextures[ 0 ] );
	pImpl->BlurMultipass( pImpl->mFirstPassTextures );

	pImpl->Downsample( pImpl->mFirstPassTextures[ 0 ], pImpl->mSecondPassTextures[ 0 ] );
	pImpl->BlurMultipass( pImpl->mSecondPassTextures );

	pImpl->Add( pImpl->mFirstPassTextures[ 0 ], pImpl->mSecondPassTextures[ 0 ], pImpl->mFirstPassTextures[ 1 ] );
	pImpl->mFirstPassTextures[ 1 ].display();
	pImpl->Add( input, pImpl->mFirstPassTextures[ 1 ], output );
}
コード例 #10
0
ファイル: PostBloom.cpp プロジェクト: JonnyPtn/xygine
//public
void PostBloom::apply(const sf::RenderTexture& src, sf::RenderTarget& dest)
{
    initTextures(src.getSize());

    filterBright(src, m_brightnessTexture);

    downSample(m_brightnessTexture, m_firstPassTextures[0]);

    blurMultipass(m_firstPassTextures);

    downSample(m_firstPassTextures[0], m_secondPassTextures[0]);

    blurMultipass(m_secondPassTextures);

    add(m_firstPassTextures[0], m_secondPassTextures[0], m_firstPassTextures[1]);
    m_firstPassTextures[1].display();

    add(src, m_firstPassTextures[1], dest);
}
コード例 #11
0
ファイル: LightMap.hpp プロジェクト: DeMoully/SFML_Extensions
		void        draw      (sf::RenderTarget & target, sf::RenderStates states = sf::RenderStates::Default) const
		{
			lightBuffer.clear();
			texture.display();
			states.texture = &texture.getTexture();
			for (const auto & light : lights)
			{
				light.draw(lightBuffer, getView(), states);
			}
			sf::Vector2f dimensions = sf::Vector2f(texture.getSize());
			sf::VertexArray vertices(sf::Quads, 4);
			vertices[0] = sf::Vertex(sf::Vector2f(0.f, 0.f), sf::Color(255, 255, 255, minAlpha), sf::Vector2f(0.f, 0.f));
			vertices[1] = sf::Vertex(sf::Vector2f(dimensions.x, 0.f), sf::Color(255, 255, 255, minAlpha), sf::Vector2f(dimensions.x, 0.f));
			vertices[2] = sf::Vertex(dimensions, sf::Color(255, 255, 255, minAlpha), dimensions);
			vertices[3] = sf::Vertex(sf::Vector2f(0.f, dimensions.y), sf::Color(255, 255, 255, minAlpha), sf::Vector2f(0.f, dimensions.y));
			lightBuffer.draw(vertices, states);
			lightBuffer.display();
			target.draw(sf::Sprite(lightBuffer.getTexture()));
		}