Exemplo n.º 1
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);
    }
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
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();
		}
	}
Exemplo n.º 4
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);	
}
Exemplo n.º 5
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 );
			}
		}
	}
Exemplo n.º 6
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);
	};
Exemplo n.º 7
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();
}
Exemplo n.º 8
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();
	}
Exemplo n.º 9
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()));
		}
Exemplo n.º 10
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 );
	}
}
Exemplo n.º 11
0
void AppStateSplashScreen::render_splash(sf::RenderTexture& texture, int frame)
{
  texture.draw(m_splash_sprite);
  texture.display();
}
Exemplo n.º 12
0
		void        draw      (const sf::Drawable & drawable, sf::RenderStates states = sf::RenderStates::Default) const
		{
			texture.draw(drawable, states);
		}
Exemplo n.º 13
0
Arquivo: main.cpp Projeto: Dka8/rltk
void draw_bg(layer_t * l, sf::RenderTexture &window) {
	sf::Texture * bg = get_texture("backdrop");
	sf::Sprite backdrop(*bg);
	window.draw(backdrop);
}
Exemplo n.º 14
0
int main(){
	Node* head = new Node(SIZE / 2,SIZE/2,UP);
	head->next = new Node(SIZE/2,SIZE/2-1,UP);
	head->next->next = new Node(SIZE/2,SIZE/2 - 2,UP);
	head->next->next->next = new Node(SIZE/2,SIZE/2-3,UP);
	head->next->next->next->next = new Node(SIZE/2,SIZE/2-4,UP);
	head->next->next->next->next->next = nullptr;
	float speed = 150;
	sf::SoundBuffer soundBuffer;
	soundBuffer.loadFromFile("boop.wav");
	sf::Sound sound;
	sound.setBuffer(soundBuffer);
	gameOver = false;
	  srand (time(NULL));

	//sq[32][32] = UP;
	//sq[32][31] = UP;
	//sq[32][30] = UP;
	//sq[32][29] = UP;
	//sq[32][28] = UP;
	for(int x = 0; x <SIZE; x++){
		for( int y = 0; y < SIZE; y++){
			blacklist[x][y] = false;
		}
	}
	

	sf::RenderWindow window(sf::VideoMode(640, 640, 32), "Snake", sf::Style::Titlebar | sf::Style::Close);
	sf::Clock clock;
	clock.restart();
	sf::Event windowEvent;
	renderTexture.create(640,640);
	renderTexture.display();
	sf::Texture gameOverScreen;
	gameOverScreen.loadFromFile("gameover.png", sf::IntRect(320,192,640,640));
	sf::Sprite sprite;
	sprite.setTexture(gameOverScreen);
	bool upPress, downPress, leftPress, rightPress = false;
	int addCount = 0;
	int soundCount = 0;

	while(window.isOpen()){
		bool anyEvent = false ;
		while (window.pollEvent(windowEvent))
		{//Event Handling
			anyEvent = true;
			switch (windowEvent.type)
			{
				//running = false;
			case sf::Event::KeyPressed:
				if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)){
					//std::cout << "left" << leftPress <<"\n";
					if(head->dir != RIGHT && !leftPress){
						head->dir = LEFT;
						leftPress = true;
					}
				}else{
					leftPress = false;
				}

				if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)){
					//std::cout << "right\n";
					if(head->dir != LEFT && !rightPress){
						head->dir = RIGHT;
						rightPress = true;
					}
				}else{
					//std::cout << "rightcall";
					rightPress = false;
				}

				if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)){//inverted
					//std::cout << "down\n";
					if(head->dir != DOWN && !upPress){
						head->dir = UP;
						upPress = true;
					}
				}else{
					upPress = false;
				}


				if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)){//inverted
					//std::cout << "up\n";
					if(head->dir != UP && !downPress){
						head->dir = DOWN;
						downPress = true;
					}
				}else{
					downPress = false;
				}

				break;

			case sf::Event::Closed:
				//delete head;
				window.close();
				break;

			}
		}//\EventHandling
		if(!anyEvent){
			leftPress = false;
			rightPress = false;
			upPress = false;
			downPress = false;
		}
		anyEvent = false;


		//for(int x = 0; x < 64; ++x){
		//	for(int y = 0; y < 64; ++y){
		sf::Time t = clock.getElapsedTime();
		if(t.asMilliseconds() > speed){
			updatePos(*head);
			updateDir(*head);
			soundCount++;
			if(soundCount > 5){
				sound.play();
				soundCount = 0;
			}
			clock.restart();
			if(!gameOver)
				gameOver = !checkBounds(*head);
			checkIntersect(*head);//gen blacklist
			if(addCount > 0){
				--addCount;
				Node* end = getEnd(*head);
				switch(end->dir){
				case UP:
					end->next = new Node(end->x, end->y - 1, end->dir);//backwards
					break;
				case DOWN:
					end->next = new Node(end->x, end->y + 1, end->dir);//backwards
					break;
				case LEFT:
					end->next = new Node(end->x + 1, end->y, end->dir);//backwards
					break;
				case RIGHT:
					end->next = new Node(end->x - 1, end->y, end->dir);//backwards
					break;}
				end->next->next = nullptr;
			}

			if(newFood){
				addCount = 4;
				if(speed >100){
				speed *= .95;
				//sound.setPitch(sound.getPitch()*1.1);
				}
				foodX = rand() % SIZE;
				foodY = rand() % SIZE;
				while(blacklist[foodX][foodY] == true){
					foodX = rand() % SIZE;
					foodY = rand() % SIZE;
				}

				newFood = false;
			}
		}
		if(gameOver){
			window.draw(sprite);
			window.display();
			gameOver = false;
			sf::Time t = sf::seconds(.5);
			for(int i = 0; i < 6; ++i)
			sf::sleep(t);
			delete head->next;
			head->x = SIZE/2;
			head->y = SIZE/2;
			head->next = new Node(SIZE/2,SIZE/2-1,UP);
			head->next->next = new Node(SIZE/2,SIZE/2 - 2,UP);
			head->next->next->next = new Node(SIZE/2,SIZE/2-3,UP);
			head->next->next->next->next = new Node(SIZE/2,SIZE/2-4,UP);
			head->next->next->next->next->next = nullptr;
			float speed = 150;
			foodX = SIZE*.75;
			foodY = SIZE*.75;
			newFood = false;
		}
		if(!gameOver){
			displaySnake(*head);
			
			sf::RectangleShape draw1 = sf::RectangleShape(sf::Vector2f(640/SIZE,640/SIZE));
			draw1.setPosition(sf::Vector2f(foodX * (640/SIZE), foodY * (640/SIZE)));
			draw1.setFillColor(sf::Color::White);
			renderTexture.draw(draw1);
		}
		sf::Texture texture = renderTexture.getTexture();
		// draw it to the window
		sf::Sprite sprite(texture);
		window.draw(sprite);
		window.display();
		renderTexture.clear();
		for(int x = 0; x < SIZE; x++){
			for( int y = 0; y < SIZE; y++){
				blacklist[x][y] = false;
			}
		}
	}
}
Exemplo n.º 15
0
void LightDirectionEmission::render(const sf::View &view, sf::RenderTexture &lightTempTexture, sf::RenderTexture &antumbraTempTexture, const std::vector<QuadtreeOccupant*> &shapes, sf::Shader &unshadowShader, float shadowExtension) {
	lightTempTexture.setView(view);

	LightSystem::clear(lightTempTexture, sf::Color::White);

	// Mask off light shape (over-masking - mask too much, reveal penumbra/antumbra afterwards)
	for (int i = 0; i < shapes.size(); i++) {
		LightShape* pLightShape = static_cast<LightShape*>(shapes[i]);

		// Get boundaries
		std::vector<LightSystem::Penumbra> penumbras;
		std::vector<int> innerBoundaryIndices;
		std::vector<int> outerBoundaryIndices;
		std::vector<sf::Vector2f> innerBoundaryVectors;
		std::vector<sf::Vector2f> outerBoundaryVectors;

		LightSystem::getPenumbrasDirection(penumbras, innerBoundaryIndices, innerBoundaryVectors, outerBoundaryIndices, outerBoundaryVectors, pLightShape->_shape, _castDirection, _sourceRadius, _sourceDistance);

		if (innerBoundaryIndices.size() != 2 || outerBoundaryIndices.size() != 2)
			continue;

		LightSystem::clear(antumbraTempTexture, sf::Color::White);

		antumbraTempTexture.setView(view);

		sf::ConvexShape maskShape;

		float maxDist = 0.0f;

		for (int j = 0; j < pLightShape->_shape.getPointCount(); j++)
			maxDist = std::max(maxDist, vectorMagnitude(view.getCenter() - pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(j))));

		float totalShadowExtension = shadowExtension + maxDist;

		maskShape.setPointCount(4);

		maskShape.setPoint(0, pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[0])));
		maskShape.setPoint(1, pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[1])));
		maskShape.setPoint(2, pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[1])) + vectorNormalize(innerBoundaryVectors[1]) * totalShadowExtension);
		maskShape.setPoint(3, pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[0])) + vectorNormalize(innerBoundaryVectors[0]) * totalShadowExtension);

		maskShape.setFillColor(sf::Color::Black);

		antumbraTempTexture.draw(maskShape);

		sf::VertexArray vertexArray;

		vertexArray.setPrimitiveType(sf::PrimitiveType::Triangles);

		vertexArray.resize(3);

		{
			sf::RenderStates states;
			states.blendMode = sf::BlendAdd;
			states.shader = &unshadowShader;

			// Unmask with penumbras
			for (int j = 0; j < penumbras.size(); j++) {
				unshadowShader.setParameter("lightBrightness", penumbras[j]._lightBrightness);
				unshadowShader.setParameter("darkBrightness", penumbras[j]._darkBrightness);

				vertexArray[0].position = penumbras[j]._source;
				vertexArray[1].position = penumbras[j]._source + vectorNormalize(penumbras[j]._lightEdge) * totalShadowExtension;
				vertexArray[2].position = penumbras[j]._source + vectorNormalize(penumbras[j]._darkEdge) * totalShadowExtension;

				vertexArray[0].texCoords = sf::Vector2f(0.0f, 1.0f);
				vertexArray[1].texCoords = sf::Vector2f(1.0f, 0.0f);
				vertexArray[2].texCoords = sf::Vector2f(0.0f, 0.0f);

				antumbraTempTexture.draw(vertexArray, states);
			}
		}

		antumbraTempTexture.display();

		// Multiply back to lightTempTexture
		sf::RenderStates antumbraRenderStates;
		antumbraRenderStates.blendMode = sf::BlendMultiply;

		sf::Sprite s;

		s.setTexture(antumbraTempTexture.getTexture());

		lightTempTexture.setView(lightTempTexture.getDefaultView());

		lightTempTexture.draw(s, antumbraRenderStates);

		lightTempTexture.setView(view);
	}

	for (int i = 0; i < shapes.size(); i++) {
		LightShape* pLightShape = static_cast<LightShape*>(shapes[i]);

		if (pLightShape->_renderLightOverShape) {
			pLightShape->_shape.setFillColor(sf::Color::White);

			lightTempTexture.draw(pLightShape->_shape);
		}
	}

	// Multiplicatively blend the light over the shadows
	sf::RenderStates lightRenderStates;
	lightRenderStates.blendMode = sf::BlendMultiply;

	lightTempTexture.setView(lightTempTexture.getDefaultView());

	lightTempTexture.draw(_emissionSprite, lightRenderStates);

	lightTempTexture.display();
}
Exemplo n.º 16
0
  void onRender(sf::RenderWindow &window, double time, double deltaTime)
  {
    double thermalViewYawRange = thermalViewPitchRange/windowHeight*windowWidth;
    double vxmin = 0.0;//viewYaw-thermalViewYawRange/2.0;
    double vxmax = 360.0;//viewYaw+thermalViewYawRange/2.0;
    double vymin = 0;//viewPitch-thermalViewPitchRange/2.0;
    double vymax = thermalObservedPitchRange;//viewPitch+thermalViewPitchRange/2.0;

    double cursorTemp = 0.0;
    double cursorOverlap = 0.0;

    window.clear(sf::Color::Black);

    sf::RectangleShape pixel;
    //pixel.setSize(sf::Vector2f(thermalViewPixelSize, thermalViewPixelSize));

    if(sf::Keyboard::isKeyPressed(sf::Keyboard::P)) {
      viewImage.clear();
      for(int px = 0; px < windowWidth; px += thermalViewPixelSize) {
        for(int py = 0; py < windowHeight; py += thermalViewPixelSize) {
          updatedPixels.push_back(sf::Vector2<int>(px, py));
        }
      }
    } else if(sf::Keyboard::isKeyPressed(sf::Keyboard::C)) {
      /*std::vector<RectTree<SensorReading>::RectResult> resList;
      readingsTree.retrieveAllRects(resList);
      readingsTree.removeResults(resList);*/
      viewImage.clear();
      readingsTree.reset(0.0, 0.0, 360.0, thermalObservedPitchRange, 4);
    }

    //std::deque< sf::Vector2<int> >::iterator iter = updatedPixels.begin();
    auto iter = updatedPixels.begin();
    for(; iter != updatedPixels.end(); iter++) {
      int px = iter->x, py = iter->y;

      double vx = vxmin+(vxmax-vxmin)*((double)px/(double)windowWidth );
      double vy = vymin+(vymax-vymin)*((double)py/(double)windowHeight);
      double vw = thermalPixelSizeYaw;
      double vh = thermalPixelSizePitch;

      std::vector<RectTree<SensorReading>::RectResult> resList;
      readingsTree.findRectsAtPoint(vx, vy, resList);

      std::vector<RectTree<SensorReading>::RectResult> delList;

      pixel.setPosition(sf::Vector2f(px, py));
      pixel.setSize(sf::Vector2f(
        thermalViewPixelSize,
        thermalViewPixelSize //(double)thermalViewPixelSize/(double)windowWidth*(double)windowHeight
      ));

      double temp = 0.0; int count = 0; double sum = 0;
      RectTree<SensorReading>::RectResult *oldestRes = NULL; double oldestTime = 0.0;
      std::vector<RectTree<SensorReading>::RectResult>::iterator iter = resList.begin();
      for(; iter != resList.end(); iter++) {
        RectTree<SensorReading>::RectResult &res = *iter;
        double age = time-res.rect->value.time;
        /*if(res.rect->value.time < oldestTime || oldestRes == NULL) {
          oldestTime = res.rect->value.time;
          oldestRes = &res;
        }*/
        double ageScalar = 1.0/(1.0+age);
        temp += res.rect->value.temp*ageScalar;
        sum += ageScalar;
        count++;
      }
      if(count > 40) {
        delList.insert(delList.end(), resList.begin(), resList.begin()+10);
      }
      temp /= sum;
      if(count > 0) {
        pixel.setFillColor(getThermalPixelColor(temp));
      } else {
        pixel.setFillColor(sf::Color::Black);
      }
      viewImage.draw(pixel);
      if(
            cursorX > px && cursorX < px+thermalViewPixelSize
        &&  cursorY > py && cursorY < py+thermalViewPixelSize
      ) {
        cursorTemp = temp;
      }

      readingsTree.removeResults(delList);
    }
    int updatedPixelCount = updatedPixels.size();
    updatedPixels.clear();

    viewImage.display();
    sf::Sprite sprite(viewImage.getTexture());
    window.draw(sprite);


    if(0) {
      std::vector<RectTree<SensorReading>::RectResult> resList;
      readingsTree.retrieveAllRects(resList);

      std::vector<RectTree<SensorReading>::RectResult>::iterator iter = resList.begin();
      for(; iter != resList.end(); iter++) {
        RectTree<SensorReading>::RectResult &res = *iter;
        double px = res.rect->x/vxmax*windowWidth;
        double py = res.rect->y/vymax*windowHeight;
        double pw = res.rect->w/vxmax*windowWidth;
        double ph = res.rect->h/vymax*windowHeight;
        pixel.setFillColor(sf::Color(255*(double)res.rect->value.temp/30.0, 50, 50, 100));
        pixel.setPosition(sf::Vector2f(px, py));
        pixel.setSize(sf::Vector2f(pw, ph));
        sf::RenderStates rs;
        rs.blendMode = sf::BlendAlpha;
        window.draw(pixel);
      }
    }
    if(1) {
      pixel.setFillColor(sf::Color(255, 255, 255));
      std::vector<RectTree<SensorReading>::RectResult> resList;
      double cvx = (double)cursorX/(double)windowWidth*vxmax;
      double cvy = (double)cursorY/(double)windowHeight*vymax;
      readingsTree.findRectsAtPoint(cvx, cvy, resList);

      updatedPixels.push_back(sf::Vector2<int>(
        floor(cursorX/thermalViewPixelSize)*thermalViewPixelSize,
        floor(cursorY/thermalViewPixelSize)*thermalViewPixelSize
      ));
      
      std::vector<RectTree<SensorReading>::RectResult>::iterator iter = resList.begin();
      for(; iter != resList.end(); iter++) {
        RectTree<SensorReading>::RectResult &res = *iter;
        double px = res.rect->x/vxmax*windowWidth;
        double py = res.rect->y/vymax*windowHeight;
        double pw = res.rect->w/vxmax*windowWidth;
        double ph = res.rect->h/vymax*windowHeight;
        pixel.setPosition(sf::Vector2f(px, py));
        pixel.setSize(sf::Vector2f(pw, ph));
        window.draw(pixel);
        cursorOverlap++;
      }

      // RectTree<SensorReading>::Node &node = readingsTree.getNodeAtPoint(cvx, cvy);
      // pixel.setPosition(sf::Vector2f(node.x/vxmax*windowWidth, node.y/vymax*windowHeight));
      // pixel.setSize(sf::Vector2f(node.w/vxmax*windowWidth, node.h/vymax*windowHeight));
      // pixel.setFillColor(sf::Color::Green);
      // window.draw(pixel);
    }

    sf::Text text;
    text.setFont(font);
    std::stringstream ss;
    ss << viewYaw << ", " << viewPitch << "; "
       << drAlpha << ", " << drGamma
       << " -- " << cursorTemp << ", " << cursorOverlap
       << " -- " << 1/deltaTime << "FPS, " << updatedPixelCount
    ;
    text.setString(ss.str());
    text.setCharacterSize(24);
    text.setColor(sf::Color::White);

    window.draw(text);
    window.display();
  }
Exemplo n.º 17
0
	void StaticImage::render(sf::RenderTexture &renderTexture, const sf::Vector2f &offset)
	{
		sf::Transform transform;
		transform.translate(offset);
		renderTexture.draw(mSprite, transform);
	}
Exemplo n.º 18
0
void LightPointEmission::render(const sf::View &view, sf::RenderTexture &lightTempTexture, sf::RenderTexture &emissionTempTexture, sf::RenderTexture &antumbraTempTexture, const std::vector<QuadtreeOccupant*> &shapes, sf::Shader &unshadowShader, sf::Shader &lightOverShapeShader) {
	LightSystem::clear(emissionTempTexture, sf::Color::Black);

	emissionTempTexture.setView(view);

	emissionTempTexture.draw(_emissionSprite);

	emissionTempTexture.display();
	
	LightSystem::clear(lightTempTexture, sf::Color::Black);

	lightTempTexture.setView(view);

	lightTempTexture.draw(_emissionSprite);

	sf::Transform t;
	t.translate(_emissionSprite.getPosition());
	t.rotate(_emissionSprite.getRotation());
	t.scale(_emissionSprite.getScale());

	sf::Vector2f castCenter = t.transformPoint(_localCastCenter);

	float shadowExtension = _shadowOverExtendMultiplier * (getAABB().width + getAABB().height);

	struct OuterEdges {
		std::vector<int> _outerBoundaryIndices;
		std::vector<sf::Vector2f> _outerBoundaryVectors;
	};

	std::vector<OuterEdges> outerEdges(shapes.size());

	// Mask off light shape (over-masking - mask too much, reveal penumbra/antumbra afterwards)
	for (unsigned i = 0; i < shapes.size(); i++) {
		LightShape* pLightShape = static_cast<LightShape*>(shapes[i]);

		// Get boundaries
		std::vector<int> innerBoundaryIndices;
		std::vector<sf::Vector2f> innerBoundaryVectors;
		std::vector<LightSystem::Penumbra> penumbras;

		LightSystem::getPenumbrasPoint(penumbras, innerBoundaryIndices, innerBoundaryVectors, outerEdges[i]._outerBoundaryIndices, outerEdges[i]._outerBoundaryVectors, pLightShape->_shape, castCenter, _sourceRadius);

		if (innerBoundaryIndices.size() != 2 || outerEdges[i]._outerBoundaryIndices.size() != 2)
			continue;

		// Render shape
		if (!pLightShape->_renderLightOverShape) {
			pLightShape->_shape.setFillColor(sf::Color::Black);

			lightTempTexture.draw(pLightShape->_shape);
		}

		sf::RenderStates maskRenderStates;
		maskRenderStates.blendMode = sf::BlendNone;

		sf::Vector2f as = pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(outerEdges[i]._outerBoundaryIndices[0]));
		sf::Vector2f bs = pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(outerEdges[i]._outerBoundaryIndices[1]));
		sf::Vector2f ad = outerEdges[i]._outerBoundaryVectors[0];
		sf::Vector2f bd = outerEdges[i]._outerBoundaryVectors[1];

		sf::Vector2f intersectionOuter;

		// Handle antumbras as a seperate case
		if (rayIntersect(as, ad, bs, bd, intersectionOuter)) {
			sf::Vector2f asi = pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[0]));
			sf::Vector2f bsi = pLightShape->_shape.getTransform().transformPoint(pLightShape->_shape.getPoint(innerBoundaryIndices[1]));
			sf::Vector2f adi = innerBoundaryVectors[0];
			sf::Vector2f bdi = innerBoundaryVectors[1];

			LightSystem::clear(antumbraTempTexture, sf::Color::White);

			antumbraTempTexture.setView(view);

			sf::Vector2f intersectionInner;

			if (rayIntersect(asi, adi, bsi, bdi, intersectionInner)) {
				sf::ConvexShape maskShape;

				maskShape.setPointCount(3);

				maskShape.setPoint(0, asi);
				maskShape.setPoint(1, bsi);
				maskShape.setPoint(2, intersectionInner);

				maskShape.setFillColor(sf::Color::Black);

				antumbraTempTexture.draw(maskShape);	
			}
			else {
				sf::ConvexShape maskShape;

				maskShape.setPointCount(4);

				maskShape.setPoint(0, asi);
				maskShape.setPoint(1, bsi);
				maskShape.setPoint(2, bsi + vectorNormalize(bdi) * shadowExtension);
				maskShape.setPoint(3, asi + vectorNormalize(adi) * shadowExtension);

				maskShape.setFillColor(sf::Color::Black);

				antumbraTempTexture.draw(maskShape);
			}

			// Add light back for antumbra/penumbras
			sf::VertexArray vertexArray;

			vertexArray.setPrimitiveType(sf::PrimitiveType::Triangles);

			vertexArray.resize(3);

			sf::RenderStates penumbraRenderStates;
			penumbraRenderStates.blendMode = sf::BlendAdd;
			penumbraRenderStates.shader = &unshadowShader;

			// Unmask with penumbras
			for (unsigned j = 0; j < penumbras.size(); j++) {
				unshadowShader.setParameter("lightBrightness", penumbras[j]._lightBrightness);
				unshadowShader.setParameter("darkBrightness", penumbras[j]._darkBrightness);

				vertexArray[0].position = penumbras[j]._source;
				vertexArray[1].position = penumbras[j]._source + vectorNormalize(penumbras[j]._lightEdge) * shadowExtension;
				vertexArray[2].position = penumbras[j]._source + vectorNormalize(penumbras[j]._darkEdge) * shadowExtension;

				vertexArray[0].texCoords = sf::Vector2f(0.0f, 1.0f);
				vertexArray[1].texCoords = sf::Vector2f(1.0f, 0.0f);
				vertexArray[2].texCoords = sf::Vector2f(0.0f, 0.0f);

				antumbraTempTexture.draw(vertexArray, penumbraRenderStates);
			}

			antumbraTempTexture.display();

			// Multiply back to lightTempTexture
			sf::RenderStates antumbraRenderStates;
			antumbraRenderStates.blendMode = sf::BlendMultiply;

			sf::Sprite s;

			s.setTexture(antumbraTempTexture.getTexture());

			lightTempTexture.setView(lightTempTexture.getDefaultView());

			lightTempTexture.draw(s, antumbraRenderStates);

			lightTempTexture.setView(view);
		}
		else {
			sf::ConvexShape maskShape;

			maskShape.setPointCount(4);

			maskShape.setPoint(0, as);
			maskShape.setPoint(1, bs);
			maskShape.setPoint(2, bs + vectorNormalize(bd) * shadowExtension);
			maskShape.setPoint(3, as + vectorNormalize(ad) * shadowExtension);

			maskShape.setFillColor(sf::Color::Black);

			lightTempTexture.draw(maskShape);

			sf::VertexArray vertexArray;

			vertexArray.setPrimitiveType(sf::PrimitiveType::Triangles);

			vertexArray.resize(3);

			sf::RenderStates penumbraRenderStates;
			penumbraRenderStates.blendMode = sf::BlendMultiply;
			penumbraRenderStates.shader = &unshadowShader;

			// Unmask with penumbras
			for (unsigned j = 0; j < penumbras.size(); j++) {
				unshadowShader.setParameter("lightBrightness", penumbras[j]._lightBrightness);
				unshadowShader.setParameter("darkBrightness", penumbras[j]._darkBrightness);

				vertexArray[0].position = penumbras[j]._source;
				vertexArray[1].position = penumbras[j]._source + vectorNormalize(penumbras[j]._lightEdge) * shadowExtension;
				vertexArray[2].position = penumbras[j]._source + vectorNormalize(penumbras[j]._darkEdge) * shadowExtension;

				vertexArray[0].texCoords = sf::Vector2f(0.0f, 1.0f);
				vertexArray[1].texCoords = sf::Vector2f(1.0f, 0.0f);
				vertexArray[2].texCoords = sf::Vector2f(0.0f, 0.0f);

				lightTempTexture.draw(vertexArray, penumbraRenderStates);
			}
		}
	}

	for (unsigned i = 0; i < shapes.size(); i++) {
		LightShape* pLightShape = static_cast<LightShape*>(shapes[i]);

		if (pLightShape->_renderLightOverShape) {
			pLightShape->_shape.setFillColor(sf::Color::White);

			lightTempTexture.draw(pLightShape->_shape, &lightOverShapeShader);
		}
		else {
			pLightShape->_shape.setFillColor(sf::Color::Black);

			lightTempTexture.draw(pLightShape->_shape);
		}
	}

	lightTempTexture.display();
}
Exemplo n.º 19
0
	void StaticRectangle::render(sf::RenderTexture &renderTexture, const sf::Vector2f &offset)
	{
		sf::Transform transform;
		transform.translate(offset);
		renderTexture.draw(mRect, transform);
	}
Exemplo n.º 20
0
void Graphics::draw(sf::RenderTexture &RW,sf::Sprite& Sprite){
	RW.draw(Sprite);
	sf::Sprite s;
}