SOLVED!
sf::Texture texture = renderTexture.getTexture();
doesn't copy the texture?
If i fail even then, i will probably quit sfml, it is probably not for for me.
This is a terrible attitude to have. I have many other words to describe it but I will refrain from doing so.
I think you misunderstood me i expressed poorly, the text is important and i have more then i stated at first, drawing it with sf::Text uses too much performance to do. I was unable to achieve that, so i would have to resolve to different library or method.
The issue was quite a whacky one, i stated i do not use sprites, i was unaware the sf::Sprite member "m_texture" was a const.
Fixed the issue.
The issue was not with the sf::Texture or sf::RenderTexture. It was the sf::Sprite all the time.
The reason is, as i was adding more elements to the vector, the vector reached maximum size and had to reallocate, issue comes from sf::Sprite member (const Texture* m_texture; ).
Fixed the issue with, setting size for vector before adding any elements. Or setting sf::Sprite texture before drawing.
, unsure if i was supposed to know this.
Two lines are commented out in main which fix issue.
class Dialog
{
public:
Dialog();
Dialog(const Dialog & d);
void MakeText(sf::Font & font);
sf::Texture tex;
sf::Sprite spr;
};
Dialog::Dialog(){ std::cout << "defC" << std::endl; }
Dialog::Dialog(const Dialog & d)
{
tex = d.tex;
spr = d.spr;
std::cout << "d:" << d.spr.getTexture() << std::endl;
std::cout << "s:" << spr.getTexture() << std::endl;
}
void Dialog::MakeText(sf::Font & font)
{
std::cout << "mTXT" << std::endl;
sf::Text txt;
int posX = 0, posY = 0;
txt.setCharacterSize(32);
txt.setColor(sf::Color::White);
txt.setFont(font);
txt.setString("Hello");
txt.setPosition(0, 0);
sf::RenderTexture renTex;
renTex.create(100, 100);
renTex.draw(txt);
renTex.display();
tex = renTex.getTexture();
spr.setTexture(tex, true);
spr.setPosition(1, 1);
}
int main()
{
sf::View view;
view.setViewport(sf::FloatRect(0, 0, 1, 1));
sf::RenderWindow win;
sf::VideoMode vidMod(800,600,32);
win.create(vidMod, "hello", sf::Style::Default);
win.setFramerateLimit(100);
win.setView(view);
sf::Font arial;
arial.loadFromFile("arial.ttf");
std::vector<Dialog> listDialog;
//listDialog.reserve(4);
for (unsigned int i = 0; i < 4; i++)
{
listDialog.push_back(Dialog());
listDialog.back().MakeText(arial);
}
sf::Sprite tmpSpr1, tmpSpr2, tmpSpr3;
sf::Texture tex;
tex.loadFromFile("link.png");
tmpSpr1.setTexture(tex);
tmpSpr1.setPosition(101, 0);
tmpSpr2 = tmpSpr1;
tmpSpr2.setPosition(101, 50);
tmpSpr3 = tmpSpr2;
tmpSpr3.setPosition(101, 100);
bool done = false;
while(done == false)
{
win.clear();
sf::Event event;
while(win.pollEvent(event))
{
switch(event.type)
{
case sf::Event::Closed:
done = true;
break;
default:
break;
}
}
for (unsigned int i = 0; i < listDialog.size(); i++)
{
//listDialog[i].spr.setTexture(listDialog[i].tex, true);
listDialog[i].spr.setPosition(0, i*101);
win.draw(listDialog[i].spr);
}
win.draw(tmpSpr1);
win.draw(tmpSpr2);
win.draw(tmpSpr3);
win.display();
}
return 0;
};