Hi there, I have almost the same problem with @traxys, so I don't create new topic, hope anybody help me to solve it
This is my code:
#include <SFML/Graphics.hpp>
#include <sstream>
#include <iostream>
#define WND_WIDTH 400 // Window Width
#define WND_HEIGHT 400 // Window Height
#define S_WIDTH 100 // Square Width
#define S_HEIGHT 100 // Square Height
#define SPEED 10
int main(void)
{
sf::RenderTexture rtexture;
rtexture.create(S_WIDTH,S_HEIGHT);
rtexture.setSmooth(true);
sf::Font font;
if(!font.loadFromFile("arial.ttf")) std::cout << "Error ! Can't load font file [arial.ttf]";
sf::Text text;
text.setFont(font);
text.setColor(sf::Color::Red);
text.setString("1234");
text.setCharacterSize(30);
text.setOrigin((text.getLocalBounds().width+text.getLocalBounds().left)/2,(text.getLocalBounds().height+text.getLocalBounds().top)/2);
text.setPosition(S_WIDTH/2.0,S_HEIGHT/2.0);
sf::RectangleShape square;
square.setOrigin(S_WIDTH/2,S_HEIGHT/2);
square.setOutlineThickness(2);
square.setPosition(S_WIDTH/2,S_HEIGHT/2);
square.setSize(sf::Vector2f(S_WIDTH,S_HEIGHT));
square.setFillColor(sf::Color::Black);
sf::RenderWindow window(sf::VideoMode(WND_WIDTH,WND_HEIGHT),"Testing");
window.setFramerateLimit(60);
// this is the problem
sf::RectangleShape rect;
rect.setTexture(&rtexture.getTexture(),true);
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) window.close();
}
window.clear(sf::Color::Black);
//window.draw(rect);
window.draw(square);
window.draw(text);
window.display();
}
}
Humm... I've created my texture had square and text in the middle of it by using rendertexture. But I can't getTexture() to use even though I can draw on main window ( like the code above ). When comment
window.draw(square);
window.draw(text);
and uncomment window.draw(rect), nothing on the screen, why ?