Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: [SFML2] RenderImage and Text problems  (Read 2943 times)

0 Members and 1 Guest are viewing this topic.

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
[SFML2] RenderImage and Text problems
« on: April 27, 2010, 07:50:33 pm »
Hello. I'm trying to draw some strings into sf::RenderImage . Unfortunately, it doesn't work.

Code: [Select]
#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 :)

Ashenwraith

  • Sr. Member
  • ****
  • Posts: 270
    • View Profile
[SFML2] RenderImage and Text problems
« Reply #1 on: April 28, 2010, 06:12:24 am »
The code works in the example, but..

It looks like you are trying to use a render image like a regular image.

A render image is volatile. I think you need to use GetImage to put the render image into a normal image and then place that in your sprite.

It also looks like this if you forget to clear your render image before every draw.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
[SFML2] RenderImage and Text problems
« Reply #2 on: April 28, 2010, 01:02:42 pm »
Which SFML 2 revision do you use?

Quote
A render image is volatile

No it isn't. RenderImage::GetImage() refers to the same object from the construction to the destruction of the render image. And it is a regular image.
Laurent Gomila - SFML developer

l0ud

  • Newbie
  • *
  • Posts: 23
    • View Profile
[SFML2] RenderImage and Text problems
« Reply #3 on: April 28, 2010, 03:56:15 pm »
Well... I must have been using a broken one. I've just updated SFML to the newest revision and everything works correctly now.

So, the problem is solved :) Thanks.