Hello.
I have idea: I want to draw text on screen but keep it efficient, so draw text onto renderTexture then use VertexArray to draw it on screen so save performance is the general idea.
But i am facing one thing, i cannot manipulate render texture, for example i want to delete part of it(making it transparent so i can put another text there).
Any ideas how to clear part of renderTexture.
This is how i drawn the text via vertexArray using renderTextures
int main()
{
sf::View view;
//view.setCenter(sf::Vector2f(400, 300));
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::RenderTexture renTex;
sf::Text txt;
sf::Font font;
sf::RectangleShape rec;
sf::VertexArray verArr;
font.loadFromFile("arial.ttf");
txt.setCharacterSize(24);
txt.setColor(sf::Color::Black);
txt.setFont(font);
txt.setString("Greeting young traveler!\nMay i be of any assistence?");
txt.setPosition(-txt.getLocalBounds().left, -txt.getLocalBounds().top);
sf::FloatRect tfr = txt.getLocalBounds();
rec.setPosition(-tfr.left, -tfr.top);
rec.setSize(sf::Vector2f(tfr.width + tfr.left, tfr.height + tfr.top*2));
renTex.create(tfr.width + tfr.left, tfr.height + tfr.top);
renTex.draw(txt);
renTex.display();
verArr.setPrimitiveType(sf::Quads);
for (int i = 0; i < 1; i++)
{
std::cout << " x:" << renTex.getSize().x << " y:" << renTex.getSize().y << std::endl;
verArr.append(sf::Vertex(sf::Vector2f(i, 0), sf::Color(255, 255, 255, 255), sf::Vector2f(0, 0)));
verArr.append(sf::Vertex(sf::Vector2f(i + renTex.getSize().x, 0), sf::Color(255, 255, 255, 255), sf::Vector2f(renTex.getSize().x, 0)));
verArr.append(sf::Vertex(sf::Vector2f(i + renTex.getSize().x, renTex.getSize().y), sf::Color(255, 255, 255, 255), sf::Vector2f(renTex.getSize().x, renTex.getSize().y)));
verArr.append(sf::Vertex(sf::Vector2f(i, +renTex.getSize().y), sf::Color(255, 255, 255, 255), sf::Vector2f(0, renTex.getSize().y)));
}
sf::RenderStates renSta;
renSta.texture = &renTex.getTexture();
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;
case sf::Event::KeyPressed:
switch(event.key.code)
{
case sf::Keyboard::K:
break;
default:
break;
}
break;
default:
break;
}
}
win.draw(rec);
//win.draw(spr);
win.draw(verArr, renSta);
win.display();
}
return 0;
};