Thanks for your answers, i finally completed my class, but still there is one problem...
The class should classify the entered text into lines.
This is how i want bool add_text(...) works:
It draws rectangle into renderTexture, - rectangle is filled with TEXTURE. Than is written new text under rectangle. All this stuf is copied in renderTexture and renderTexture is copied to TEXTURE, to be used in next call of add_text(...) and void draw(){.
The problem is that the rectangle is just white - not filed with TEXTURE - not just for first call of add_text(...), but every call.
class Text_manager{
public:
bool add_text(const std::string& text_worlds){
renderTexture.create(800, count * (text_size + space_size) + space_size + text_size);
renderTexture.clear();
rectangle.setTexture(&texture);
rectangle.setPosition(0,0);
rectangle.setSize(sf::Vector2f(800, count * (text_size + space_size)));
renderTexture.draw(rectangle);
renderTexture.display();
sf::Font font;
if (!font.loadFromFile("arial.ttf"))
return false;
sf::Text text;
text.setFont(font);
text.setString(text_worlds);
text.setCharacterSize(text_size);
text.setColor(sf::Color::Red);
text.setPosition(0,count * (text_size + space_size) + space_size);
renderTexture.draw(text);
renderTexture.display();
texture = renderTexture.getTexture();
count ++;
return true;
};
void set_text(int p_count, int p_text_size, int p_space_size){
count = p_count;
text_size = p_text_size;
space_size = p_space_size;
};
void draw(){
sprite.setTexture(texture);
window.draw(sprite);
};
private:
int count;
int text_size;
int space_size;
sf::RenderTexture renderTexture;
sf::RectangleShape rectangle;
sf::Sprite sprite;
sf::Texture texture;
};
thanks for help.