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

Author Topic: SFML 2.0 RenderImage problem  (Read 2011 times)

0 Members and 1 Guest are viewing this topic.

gardnerj

  • Newbie
  • *
  • Posts: 4
    • View Profile
SFML 2.0 RenderImage problem
« on: February 02, 2010, 05:30:03 am »
In this sample code below alternating red and blue squares should be shown when space is pressed, but the red square is not displayed.  This is using the SFML 2.0 branch version from Jan. 27.  This problem doesn't occur if either the first buffer.Draw(sprite) in the code is commented or the second is uncommented.  Also, it works for an older version from Dec. 17.  (compiled using MinGW/Codeblocks in Windows XP)


Code: [Select]

#include <SFML/Graphics.hpp>
int main(){
  sf::RenderWindow window(sf::VideoMode(640, 480, 32), "");

  sf::RenderImage buffer;
  buffer.Create(640, 480);
  sf::Sprite bufsprite;
  bufsprite.SetImage(buffer.GetImage());

  sf::Image image; image.Create(1, 1);
  sf::Sprite sprite(image);

  int mode = 0;
  while (window.IsOpened()){
    sf::Event event;
    while (window.GetEvent(event)){
      if (event.Type == sf::Event::KeyPressed){
        if (event.Key.Code == sf::Key::Escape) window.Close();
        else if (event.Key.Code == sf::Key::Space) mode = 1-mode;
      }
    }

    buffer.Clear();
    if (mode == 0){
      buffer.Draw(sprite);
      buffer.Draw(sf::Shape::Rectangle(0, 0, 200, 200, sf::Color(0,0,255)));
    }else{
      //buffer.Draw(sprite);
      buffer.Draw(sf::Shape::Rectangle(0, 0, 200, 200, sf::Color(255,0,0)));
    }

    buffer.Display();
    window.Draw(bufsprite);
    window.Display();
  }

  return EXIT_SUCCESS;
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 RenderImage problem
« Reply #1 on: February 02, 2010, 09:02:53 am »
Same problem for me, I'll try to fix as soon as possible.

Quick fix for you: uncomment the bloc at line 79 of src/SFML/Graphics/RenderImage.cpp (something I forgot to do in the last commit), the FBO implementation doesn't have this problem.
Laurent Gomila - SFML developer

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
SFML 2.0 RenderImage problem
« Reply #2 on: February 02, 2010, 09:48:40 am »
It's fixed. Thanks for your feedback :)
Laurent Gomila - SFML developer

gardnerj

  • Newbie
  • *
  • Posts: 4
    • View Profile
SFML 2.0 RenderImage problem
« Reply #3 on: February 02, 2010, 05:05:46 pm »
Thanks!  That was fast.  Just verifying that I downloaded the sfml 2 branch just now and the fix works for me too.