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

Author Topic: SFML 2.0 - RenderImage is cleared on first display  (Read 2230 times)

0 Members and 1 Guest are viewing this topic.

Jo

  • Newbie
  • *
  • Posts: 2
    • View Profile
SFML 2.0 - RenderImage is cleared on first display
« on: August 17, 2010, 09:56:53 pm »
Hi everyone.

I just switched to SFML 2.0 (SVN from today) and found some strange behaviour, as the following code shows:

Code: [Select]

#include <SFML/Graphics.hpp>
 
int main() {
if (!sf::RenderImage::IsAvailable())
return -1;

sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

sf::RenderImage image;
if (!image.Create(500, 500))
return -1;

sf::Sprite sprite(image.GetImage());
//window.Draw(sprite);//Uncomment to make it work as expected

image.Clear(sf::Color::Red);
while (window.IsOpened()) {
window.Clear();

window.Draw(sprite);

window.Display();
}
}

Using this code, the image will be shown black though it's been filled red before. If it's drawn onto the screen once before filling, it's red as expected.

If this is a bug, this is the report, if it's a feature, I'd like to know more about it.

Jo

panithadrum

  • Sr. Member
  • ****
  • Posts: 304
    • View Profile
    • Skyrpex@Github
    • Email
SFML 2.0 - RenderImage is cleared on first display
« Reply #1 on: August 18, 2010, 03:50:22 pm »
You need to call sf::RenderImage::Display() to update it's content. Try this instead:
Code: [Select]

#include <SFML/Graphics.hpp>
 
int main()
{
if (!sf::RenderImage::IsAvailable())
return -1;

sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window");

sf::RenderImage image;
if (!image.Create(500, 500))
return -1;
   
sf::Sprite sprite(image.GetImage());
   
image.Clear(sf::Color::Red);
image.Display(); // To update its content
while (window.IsOpened()) {
window.Clear();

window.Draw(sprite);

window.Display();
}
}

Jo

  • Newbie
  • *
  • Posts: 2
    • View Profile
SFML 2.0 - RenderImage is cleared on first display
« Reply #2 on: August 18, 2010, 06:43:51 pm »
Oh, that was too obvious. Thanks for your help.

 

anything