SFML community forums

Help => Graphics => Topic started by: chehob on June 14, 2011, 02:48:10 pm

Title: sprite rendering problem
Post by: chehob on June 14, 2011, 02:48:10 pm
Hello,
Here is the code:

Code: [Select]

#include <SFML/Graphics.hpp>

int main()
{
sf::VideoMode videoMode = sf::VideoMode(400, 300, 32);
sf::RenderWindow App(videoMode , "SFML Window");
App.SetFramerateLimit(60);

sf::Image Image;
if (!Image.LoadFromFile("xolo.png"))
{
return EXIT_FAILURE;
}

sf::Sprite Cross;
Cross.SetImage(Image);

while (App.IsOpened())
{
sf::Event Event;
while (App.PollEvent(Event))
{
// Window closed
if (Event.Type == sf::Event::Closed)
App.Close();

// [Esc] pressed
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App.Close();
}

App.Clear();

App.Draw(Cross);

App.Display();
}

    return EXIT_SUCCESS;
}

While running this program it doesnt draw the sprite, instead it draws a filled rectangle of sprite dimensions

BUT
when I add drawing the shape it actually works as supposed to be

Code: [Select]

sf::Sprite Cross;
Cross.SetImage(Image);

sf::Shape Line = sf::Shape::Line(0, 0, 0, 0, 1, sf::Color(0,0,0,0));
...

App.Clear();

App.Draw(Cross);
App.Draw(Line);

App.Display();


What's the problem here?
I'm using SFML 2.0
Title: sprite rendering problem
Post by: chehob on June 14, 2011, 03:00:08 pm
Source image: (http://i53.tinypic.com/2nu58x0.png)
Wrong: (http://i52.tinypic.com/zn4ho0.png)
Correct: (http://i53.tinypic.com/33wnr6b.png)
Title: sprite rendering problem
Post by: Laurent on June 14, 2011, 03:16:15 pm
Is it really this code that produces this output??
Title: sprite rendering problem
Post by: chehob on June 14, 2011, 03:24:33 pm
Quote from: "Laurent"
Is it really this code that produces this output??


Code that doesn't work normally:
Code: [Select]

#include <SFML/Graphics.hpp>

int main()
{
   sf::VideoMode videoMode = sf::VideoMode(400, 300, 32);
   sf::RenderWindow App(videoMode , "SFML Window");
   App.SetFramerateLimit(60);
     
   sf::Image Image;
   if (!Image.LoadFromFile("xolo.png"))
   {
      return EXIT_FAILURE;
   }

   sf::Sprite Cross;
   Cross.SetImage(Image);

   while (App.IsOpened())
   {
      sf::Event Event;
      while (App.PollEvent(Event))
      {
         // Window closed
         if (Event.Type == sf::Event::Closed)
            App.Close();

         // [Esc] pressed
         if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            App.Close();
      }

      App.Clear();

      App.Draw(Cross);

      App.Display();
   }

    return EXIT_SUCCESS;
}


This one does:
Code: [Select]

#include <SFML/Graphics.hpp>

int main()
{
   sf::VideoMode videoMode = sf::VideoMode(400, 300, 32);
   sf::RenderWindow App(videoMode , "SFML Window");
   App.SetFramerateLimit(60);
     
   sf::Image Image;
   if (!Image.LoadFromFile("xolo.png"))
   {
      return EXIT_FAILURE;
   }

   sf::Sprite Cross;
   Cross.SetImage(Image);

   sf::Shape Line = sf::Shape::Line(0, 0, 0, 0, 1, sf::Color(0,0,0,0));

   while (App.IsOpened())
   {
      sf::Event Event;
      while (App.PollEvent(Event))
      {
         // Window closed
         if (Event.Type == sf::Event::Closed)
            App.Close();

         // [Esc] pressed
         if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
            App.Close();
      }

      App.Clear();

      App.Draw(Cross);
 App.Draw(Line);

      App.Display();
   }

    return EXIT_SUCCESS;
}
Title: sprite rendering problem
Post by: Laurent on June 14, 2011, 03:26:55 pm
Weird... never seen this before :shock:

What's your OS? Graphics card? Are your graphics drivers up-to-date?
Title: sprite rendering problem
Post by: chehob on June 14, 2011, 03:30:50 pm
Quote from: "Laurent"
Weird... never seen this before :shock:

What's your OS? Graphics card? Are your graphics drivers up-to-date?

Windows 7, Intel GMA 3100, don't know about drivers. I'm at workstation now, will try same at home.