Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: is it possible to subtract a texture from an other  (Read 12988 times)

0 Members and 1 Guest are viewing this topic.

grimmreefer

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: is it possible to subtract a texture from an other
« Reply #15 on: September 21, 2012, 04:27:11 pm »
Does it mean i wont work?

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: is it possible to subtract a texture from an other
« Reply #16 on: September 21, 2012, 04:32:38 pm »
Does it mean i wont work?
It works as long as you use an alpha channel greater than 0. ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: is it possible to subtract a texture from an other
« Reply #17 on: September 21, 2012, 10:03:47 pm »
It's fixed, you can now use completely transparent shapes.
Laurent Gomila - SFML developer

grimmreefer

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: is it possible to subtract a texture from an other
« Reply #18 on: September 22, 2012, 09:34:29 am »
   8) it work fine.

but it doesn't work if i use more than one "Light"
« Last Edit: September 22, 2012, 09:38:26 am by grimmreefer »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: is it possible to subtract a texture from an other
« Reply #19 on: September 22, 2012, 10:13:31 am »
Quote
but it doesn't work if i use more than one "Light"
What happens? Can you show the code?
Laurent Gomila - SFML developer

grimmreefer

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: is it possible to subtract a texture from an other
« Reply #20 on: September 22, 2012, 10:23:11 am »
i make a class for the light, if i add an other light the visible range is at the overlab, omg my english is so bad ^^



#ifndef CLIGHTS_HPP
#define CLIGHTS_HPP

#include <iostream>
#include <SFML\Graphics.hpp>


#include <vector>
#include <string>
#include <sstream>

using namespace std;

class CLights
{
    public:

            CLights(int SizeX, int SizeY);


            void SetPosition(int PosX, int PosY);
            void SetLightSize(float Radius);
            void SetLightColor(sf::Color LightColor);
            void SetLightPosition(int PosX, int PosY);
            void BackgroundColor(sf::Color Color);

            void Draw(sf::RenderWindow &window);



    private:

            float m_Radius;

            sf::Color m_LigthColor;

            int m_PosX;
            int m_PosY;

            int m_LightPosX;
            int m_LightPosY;

            sf::CircleShape m_CircleLight;
            sf::RenderTexture m_RTex;
            sf::Sprite m_ShapeBackground;
};



#endif







#include <iostream>
#include <SFML\Graphics.hpp>
#include <SFML\Audio.hpp>

#include "Lights.hpp"

#include <string>
#include <vector>
#include <sstream>

using namespace std;

CLights::CLights(int SizeX, int SizeY)
{
    m_RTex.create(640,480);
    m_CircleLight.setRadius(0);
    m_CircleLight.setPosition(0,0);
    m_CircleLight.setFillColor(sf::Color(255,255,255,1));

    m_ShapeBackground.setTexture(m_RTex.getTexture(), true);
    m_ShapeBackground.setPosition(0,0);



}



void CLights::SetLightColor(sf::Color LightColor)
{
    m_CircleLight.setFillColor(LightColor);
}



void CLights::SetLightSize(float Radius)
{
    m_Radius = Radius;

    m_CircleLight.setRadius(m_Radius);
}



void CLights::SetLightPosition(int PosX, int PosY)
{
    m_LightPosX = PosX;
    m_LightPosY = PosY;


    m_CircleLight.setPosition(sf::Vector2f(m_LightPosX, m_LightPosY));
}

void CLights::SetPosition(int PosX, int PosY)
{
    m_PosX = PosX;
    m_PosY = PosY;

    m_CircleLight.setPosition(sf::Vector2f(m_PosX, m_PosY));
}



void CLights::BackgroundColor(sf::Color Color)
{
        m_ShapeBackground.setColor(Color);

}



void CLights::Draw(sf::RenderWindow &window)
{
    m_RTex.clear();
    m_RTex.draw(m_CircleLight, sf::BlendNone);
    m_RTex.display();

    m_ShapeBackground.setTexture(m_RTex.getTexture(), true);




    window.draw(m_ShapeBackground);
}

 
« Last Edit: September 22, 2012, 11:11:51 am by Laurent »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: is it possible to subtract a texture from an other
« Reply #21 on: September 22, 2012, 11:15:23 am »
You must draw all your lights to the same render texture. You should take some time to figure out how this code works, it seems that you have no idea what it does ;)

m_RTex.clear(sf::Color::Black); // to make it more obvious
m_RTex.draw(light1, sf::BlendNone);
m_RTex.draw(light2, sf::BlendNone);
m_RTex.draw(light3, sf::BlendNone);
...
m_RTex.display();

// no need to call it everytime
// m_ShapeBackground.setTexture(m_RTex.getTexture(), true);

window.draw(m_ShapeBackground);

So of course you need to redesign your class a little bit.

Quote
the visible range is at the overlab, omg my english is so bad
I have no idea what "overlab" means, and my dictionnary couldn't help ;D
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: is it possible to subtract a texture from an other
« Reply #22 on: September 22, 2012, 11:27:54 am »
He just meant that only the last light will should up.
Also keep in mind that if lights do overlap you'll have to draw them in the right order to the rendertexture, although it will still lead to some unwanted effects...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

grimmreefer

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: is it possible to subtract a texture from an other
« Reply #23 on: September 22, 2012, 12:14:21 pm »
I give google translate a try

but yet, I figure it already slow. this is definitely a huge help.

grimmreefer

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: is it possible to subtract a texture from an other
« Reply #24 on: September 22, 2012, 05:35:53 pm »
i tried wiht a vector but it doesn't work, one light is nice.  but with a RenderTexture there is no way to add lights if the "Game" is running.




CLights::CLights(int SizeX, int SizeY)
{
    m_SizeX = SizeX;
    m_SizeY = SizeY;

    m_RTex.create(m_SizeX, m_SizeY);




}

void CLights::AddLigth(int PosX, int PosY, int Radius, sf::Color TempColor, sf::RenderWindow &window)
{
    m_SpriteBackground.setTexture(m_RTex.getTexture(), true);
    m_SpriteBackground.setPosition(0, 0);
    m_SpriteBackground.setColor(sf::Color(0,0,0,255));

    m_CircleLight.setPosition(sf::Vector2f(Mouse.getPosition(window).x, Mouse.getPosition(window).y));
    m_CircleLight.setRadius(Radius);
    m_CircleLight.setFillColor(sf::Color(255,255,255,1));

    m_VectorShape.push_back(m_CircleLight);


}


void CLights::Draw(sf::RenderWindow &window)
{
    for(int i = 0; i < m_VectorShape.size(); i++)
    {
        m_SpriteBackground.setColor(sf::Color(0,0,0,240));
        m_RTex.clear();
        m_RTex.draw(m_VectorShape[i], sf::BlendNone);
        m_RTex.display();

        m_SpriteBackground.setTexture(m_RTex.getTexture(), true);

        window.draw(m_SpriteBackground);

    }



}
« Last Edit: September 22, 2012, 05:59:07 pm by Laurent »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: is it possible to subtract a texture from an other
« Reply #25 on: September 22, 2012, 05:58:40 pm »
Please make use of the code=cpp tag!! :)

You still don't understand how it works, don't you? Please at least try to understand it! ;)
You only have to clear and display the render texture once and not with every single light...
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: is it possible to subtract a texture from an other
« Reply #26 on: September 22, 2012, 05:59:52 pm »
Or just look at the code I posted above.
Laurent Gomila - SFML developer

grimmreefer

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: is it possible to subtract a texture from an other
« Reply #27 on: September 22, 2012, 06:27:58 pm »
@Laurent

in your code i have to write every single light in my class, i cant add lights while the program is running

@eXpl0it3r

please believe me, i try to understand  ;D

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10801
    • View Profile
    • development blog
    • Email
Re: is it possible to subtract a texture from an other
« Reply #28 on: September 22, 2012, 06:37:16 pm »
He meant that you don't call clear() and display() in ever iteration.

Lets take an easy analogy:
The window is a piece of paper with a drawing on it. The render texture is another piece of paper on top of the other one and it is just black.
Now to see what's underneath you go and cut out some parts of the black paper. After that you can look through that cutout part onto your window.

What you did in the code with the vector is. Everytime you've cut out a square, you threw away the black paper with the hole and took a new black paper and cut out the next hole. Obviously you'll always just see one hole (since you've thrown the other holes away).

What you actually want is to take the black paper, punch as many holes as you want into it and the overlay it  with the drawing paper.

Got it? ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

grimmreefer

  • Jr. Member
  • **
  • Posts: 91
    • View Profile
    • Email
Re: is it possible to subtract a texture from an other
« Reply #29 on: September 22, 2012, 07:28:26 pm »
 :( i give up, now i can place many lights bur can move the one of the playercharakter

 

anything