Beispiel #1
0
	void run()
	{
		while (m_window.isOpen())
		{
			sf::Event event;
			while (m_window.pollEvent(event))
			{
				if (event.type == sf::Event::Closed)
					m_window.close();
			}

			// Update the position of the 'flashlight' to the current mouse position
			m_pos = static_cast<sf::Vector2f>(sf::Mouse::getPosition(m_window));
			m_flashlight.setPosition(m_pos);

			// Stance-out the 'flashlight' circle
			m_layer.clear();
			m_layer.draw(m_flashlight, sf::BlendMultiply);
			m_layer.display();

			m_window.clear(sf::Color::Blue);

			// Draw the layer sprite on top of the 'scene'
			m_window.draw(m_rect);
			m_window.draw(m_sprite);

			m_window.display();
		}
	}
Beispiel #2
0
void BloomEffect::filterBright(const sf::RenderTexture& input, sf::RenderTexture& output)
{
	sf::Shader& brightness = mShaders.get(Shaders::BrightnessPass);
	brightness.setParameter("source", input.getTexture());
	applyShader(brightness, output);
	output.display();
}
Beispiel #3
0
void renderString(sf::RenderTexture& tex, sf::Font& font, const wstring& str, int x, int y, int fitInto = 0) {
    if (fitInto) {
        sf::Text text;
        text.setFont(font);
        text.setString(str);

        int s = 100;
        text.setCharacterSize(s);
        while (text.getLocalBounds().height > fitInto)
            text.setCharacterSize(--s);

        text.setString(sf::String(str));
        text.setColor(sf::Color::White);
        text.setPosition(x, y);
        tex.draw(text);
    }
    else {
        sf::Text text;
        text.setFont(font);
        text.setString(sf::String(str));
        text.setCharacterSize(100);
        text.setColor(sf::Color::White);
        text.setPosition(x, y);
        tex.draw(text);
    }
}
Beispiel #4
0
	void draw(sf::RenderTarget &tg)
	{
		if (first)
		{
			rt.clear();
			rt.draw(sprite);
			rt.draw(logo);
			if (logo.getPosition().y == 0.0)rt.draw(press);

			if (check && timer.getElapsedTime().asSeconds() < 1)
			{
				if ((int)(rand() % 10) == 3) rt.clear(sf::Color::White);
			}
		}
		else
		{
			rt.clear(sf::Color::White);
			rt.draw(system);
			rt.draw(back2);
			rt.draw(pointer);
		}
		rt.display();
		sm.draw(rt, tg);
		if (first) tg.draw(v);
	};
Beispiel #5
0
void BloomEffect::add(const sf::RenderTexture& source, const sf::RenderTexture& bloom, sf::RenderTarget& output)
{
	sf::Shader& adder = mShaders.get(Shaders::AddPass);
	adder.setParameter("source", source.getTexture());
	adder.setParameter("bloom", bloom.getTexture());
	applyShader(adder, output);
}
Beispiel #6
0
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();
}
Beispiel #7
0
void BloomEffect::blur(const sf::RenderTexture& input, sf::RenderTexture& output, sf::Vector2f offsetFactor)
{
	sf::Shader& gaussianBlur = mShaders.get(Shaders::GaussianBlurPass);
	gaussianBlur.setParameter("source", input.getTexture());
	gaussianBlur.setParameter("offsetFactor", offsetFactor);
	applyShader(gaussianBlur, output);
	output.display();
}
Beispiel #8
0
void PostBloom::add(const sf::RenderTexture& src, const sf::RenderTexture& bloom, sf::RenderTarget& dst)
{
    auto& shader = m_shaderResource.get(Shader::AdditiveBlend);

    shader.setUniform("u_sourceTexture", src.getTexture());
    shader.setUniform("u_bloomTexture", bloom.getTexture());
    applyShader(shader, dst);
}
Beispiel #9
0
void PostBloom::filterBright(const sf::RenderTexture& src, sf::RenderTexture& dst)
{
    auto& shader = m_shaderResource.get(Shader::BrightnessExtract);

    shader.setUniform("u_sourceTexture", src.getTexture());
    applyShader(shader, dst);
    dst.display();
}
Beispiel #10
0
//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);
}
Beispiel #11
0
void PostBloom::blur(const sf::RenderTexture& src, sf::RenderTexture& dst, const sf::Vector2f& offset)
{
    auto& shader = m_shaderResource.get(Shader::GaussianBlur);

    shader.setUniform("u_sourceTexture", src.getTexture());
    shader.setUniform("u_offset", offset);

    applyShader(shader, dst);
    dst.display();
}
Beispiel #12
0
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();
}
Beispiel #13
0
bool AppState::render(sf::RenderTexture& texture, int frame)
{
  texture.clear();

  if (m_preDesktopRenderFunctor) m_preDesktopRenderFunctor(texture, frame);
  the_desktop.render(texture, frame);
  if (m_postDesktopRenderFunctor) m_postDesktopRenderFunctor(texture, frame);

  texture.display();
  return true;
}
Beispiel #14
0
//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);
}
Beispiel #15
0
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();
}
Beispiel #16
0
//writes frames to file 
//directory must already exist
void record(sf::RenderTexture& in, int frameskip, std::string directory) {

	static int frame = 0;

	if(frameskip > 0 && frame % frameskip == 0) {
		in.display();
		sf::Texture outTx = in.getTexture();
		sf::Image outImg = outTx.copyToImage();
		std::stringstream ugh;
		ugh << directory << "/" << frame << ".png";
		outImg.saveToFile(ugh.str());
	}
	frame++;
}
Beispiel #17
0
void Champion::draw(sf::RenderTexture &texture)
{
    sf::CircleShape championShape(10);
    championShape.setPosition(_location.x - 10, _location.y - 10);
    championShape.setFillColor(sf::Color(99, 184, 255));
    texture.draw(championShape);
}
Beispiel #18
0
	void generateSpot()
	{
		m_flashlightTexture.clear();

		// Draw 6 circles with increasing transparency
		for (unsigned int i = 0; i < 6; ++i)
		{
			sf::CircleShape temp(30.f - (i*2.f));
			temp.setOrigin(sf::Vector2f(30.f - (i*2.f), 30.f - (i*2.f)));
			temp.setFillColor(sf::Color(255, 255, 255, 101 - (i * 20)));
			temp.setPosition(sf::Vector2f(30.f, 30.f));

			m_flashlightTexture.draw(temp, sf::BlendNone);
		}

		//m_flashlightTexture.display();
	}
Beispiel #19
0
void displaySnake(Node &node)
{
	draw.setPosition(sf::Vector2f(node.x * (640/SIZE), node.y * (640/SIZE)));
	draw.setFillColor(sf::Color::White);
	//draw.setFillColor(sf::Color::Black);
	renderTexture.draw(draw);
	if(node.next != nullptr)
		displaySnake(*node.next);	
}
Beispiel #20
0
	void Light::render( sf::RenderTexture& target ) 
	{
		if (mOnOff == true)
		{
			if(mDirection == RIGHT)
				mSprite.setTextureRect(sf::IntRect (mRect.width*(int)mAnimationTimer, mAnimationPicY * mRect.height,mRect.width,mRect.height));
			else if(mDirection == LEFT)
				mSprite.setTextureRect(sf::IntRect(mRect.width*((int)mAnimationTimer+1),mAnimationPicY * mRect.height,-mRect.width,mRect.height));

			if(mAddBlend)
			{
				target.draw( mSprite, sf::BlendAdd );
			}
			else
			{
				target.draw( mSprite );
			}
		}
	}
void ShaderManager::draw(sf::RenderTexture &rt, sf::RenderTarget &target)
{
	sf::Sprite sprite(rt.getTexture());

	sf::RenderTexture tempRenderTexture;
	tempRenderTexture.create(WIDTH, HEIGHT);

	if (mWorking)
	{
		mShader.setParameter("texture", rt.getTexture());
		tempRenderTexture.draw(sprite, &mVingette);
		sf::Sprite tempSpr(tempRenderTexture.getTexture());
		target.draw(tempSpr, &mShader);
	}
	else
	{
		mVingette.setParameter("texture", rt.getTexture());
		target.draw(sprite, &mVingette);
	}
}
Beispiel #22
0
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);
}
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);
}
Beispiel #24
0
	Application() :
		m_window(sf::VideoMode(300, 300), "Flashlight!"),
		m_layer(),
		m_rect(sf::Vector2f(100.f, 100.f)),
		m_pos(0.f, 0.f)
	{
		m_window.setFramerateLimit(60);
		m_window.setMouseCursorVisible(false);

		m_layer.create(300, 300);
		m_flashlightTexture.create(60, 60);

		// We want to have semi-transparent edges.
		generateSpot();

		m_flashlight.setTexture(m_flashlightTexture.getTexture(), true);
		m_flashlight.setPosition(150.f, 150.f);
		m_flashlight.setOrigin(30.f, 30.f);

		m_rect.setFillColor(sf::Color::Red);
		m_rect.setPosition(100.f, 100.f);

		m_sprite.setTexture(m_layer.getTexture());
	}
Beispiel #25
0
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 );
}
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);
}
Beispiel #27
0
//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);
}
Beispiel #28
0
  ThermalScannerApp()
    : readingsTree(
        0.0, 0.0, 360.0, thermalObservedPitchRange, 4
      )
    , scannerThread(&ThermalScannerApp::scannerThreadFunc, this)
    , httpdThread(&ThermalScannerApp::httpdThreadFunc, this)
    , wsdThread(&ThermalScannerApp::wsdThreadFunc, this)
  {
    isRunning = true;

    viewPitch = thermalViewPitchRange/2.0;
    viewYaw = 180.0;
    isViewLockedToDeviceOrientation = false;

    prevThermalUpdateTime = 0.0;

    viewImage.create(windowWidth, windowHeight);

    for(int i = 0; i < 0; i++) {
      RectTree<SensorReading>::Rect rect(
        (double)rand()/(double)RAND_MAX*360.0,
        (double)rand()/(double)RAND_MAX*thermalObservedPitchRange,
        (double)rand()/(double)RAND_MAX*50.0,
        (double)rand()/(double)RAND_MAX*50.0,
        SensorReading((double)rand()/(double)RAND_MAX*30.0, 5)
      );
      readingsTree.add(rect);
    }

    if(!font.loadFromFile("Arial Black.ttf")) {
      throw std::runtime_error("Unable to load font!");
    }

    sensorUpdateDelay = 35;
    scannerThread.launch();

    httpdThread.launch();

    //wsdThread.launch();
    wsdThread.launch();
  }
Beispiel #29
0
		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()));
		}
Beispiel #30
0
void BGForced::draw( sf::RenderTexture &screen )
{
	if ( Background::pos_ready && Background::spd_ready )
	{
		if ( Background::speed_x != 0 )
		{
			// recalculate the pos_x
			// reset back if overflow
			// OUTSIDE of screen only, the value must be <= 0
			Background::draw_x += Background::speed_x;

				while ( Background::draw_x > 0 )
					Background::draw_x -= Background::tex_w;
				while ( Background::draw_x < ( Background::tex_w * -1 ) )
					Background::draw_x += Background::tex_w;

		}

		if ( Background::speed_y != 0 )
		{
			// recalculate the pos_y
			// reset back if overflow
			// OUTSIDE of screen only, the value must be <= 0
			Background::draw_y += Background::speed_y;

				while ( Background::draw_y > 0 )
					Background::draw_y -= Background::tex_h;
				while ( Background::draw_y < ( Background::tex_h * -1 ) )
					Background::draw_y += Background::tex_h;
		}
		//printf("draw x %i y %i\n", Background::draw_x, Background::draw_y);

		sf::Sprite SPR;
		SPR.setTexture( Background::texture );
		SPR.setTextureRect( sf::IntRect(0, 0, Background::draw_w, Background::draw_h) );
		SPR.setPosition( Background::draw_x, Background::draw_y );
		screen.draw( SPR );
	}
}