Hello. I'm trying to draw some strings into sf::RenderImage . Unfortunately, it doesn't work.
#include <SFML/Graphics.hpp>
int main()
{
// First of all: make sure that rendering to image is supported
if (!sf::RenderImage::IsAvailable())
return -1;
// Create a new render-window
sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");
// Create a new render-image
sf::RenderImage image;
if (!image.Create(500, 500))
return -1;
// The main loop
while (window.IsOpened())
{
// Event processing
// ...
// Clear the whole image with red color
image.Clear(sf::Color::Red);
// Draw stuff to the image
sf::Text text("String test", sf::Font::GetDefaultFont(), 12);
//image.Draw(sprite); // sprite is a sf::Sprite
//image.Draw(shape); // shape is a sf::Shape
image.Draw(text); // text is a sf::Text
// We're done drawing to the image
image.Display();
// Now we start rendering to the window, clear it first
window.Clear();
// Draw the image
sf::Sprite sprite(image.GetImage());
window.Draw(sprite);
// Uncomment this line to draw text directly
// window.Draw(text);
// End the current frame and display its contents on screen
window.Display();
}
return 0;
}
The text doesn't appear. When I'm drawing it directy into sf::RenderWindow, it does.
In my more complex app I've got even more weird results:
...but it was when I forgot to call RenderImage::Display(). Now the result is the same.
So... Is it a bug or my mistake?
Thanks for any help