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

Author Topic: Arch Linux, SFML2, Drawing sprites through static class  (Read 4407 times)

0 Members and 1 Guest are viewing this topic.

ritave

  • Newbie
  • *
  • Posts: 26
    • View Profile
Arch Linux, SFML2, Drawing sprites through static class
« on: December 12, 2010, 02:48:54 pm »
When drawing sprites on window which is in static class, you get really weird artifacts. Here's the download to minimal example which has a png and somewhat minimal code.
http://www.mediafire.com/?5gk2434jg3w2oo4

I'm working on a MSI Wind u120 with Arch Linux, and myself compiled and updated sfml2, no changes made to the source. The distro is up to date

If you want to have a quick glance at code:
Code: [Select]
#include <SFML/Graphics.hpp>

class CWindow
{
private:
static sf::RenderWindow Window;
public:
static void Init(unsigned int Width, unsigned int Height, int Style=sf::Style::Default)
{
Window.Create(sf::VideoMode(Width,Height), "", Style);
}
static bool IsOpened()
{
return Window.IsOpened();
}
static void Clear(sf::Color Color=sf::Color(0,0,0))
{
Window.Clear(Color);
}
static void Draw(const sf::Drawable &Drawable)
{
Window.Draw(Drawable);
}
static void Display()
{
Window.Display();
sf::Sleep(0);
}
static bool GetEvent(sf::Event& Event)
{
return Window.GetEvent(Event);
}
static void Close()
{
Window.Close();
}
};

sf::RenderWindow CWindow::Window;

int main()
{
sf::Image CornerImage;
CornerImage.LoadFromFile("Corner.png");
sf::Sprite Corner;
Corner.SetImage(CornerImage);

CWindow::Init(100,100);

while (CWindow::IsOpened())
{
sf::Event Event;
while (CWindow::GetEvent(Event))
{
if (Event.Type==sf::Event::Closed)
CWindow::Close();
}

CWindow::Clear(sf::Color(255,255,0));
CWindow::Draw(Corner);
CWindow::Display();
}
}

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Arch Linux, SFML2, Drawing sprites through static class
« Reply #1 on: December 12, 2010, 03:18:42 pm »
Quote
When drawing sprites on window which is in static class, you get really weird artifacts

What kind of artifacts?
Does it work if the window is local to the main function? A global variable? A global/static pointer to a sf::RenderWindow which is allocated in CWindow::Init? What happens if you create the image and sprite after calling CWindow::Init? ...
You should play a little bit with this minimal code, so that we know exactly in what context the bug shows.

Quote
Here's the download to minimal example which has a png and somewhat minimal code.

Works for me on Windows.
Laurent Gomila - SFML developer

ritave

  • Newbie
  • *
  • Posts: 26
    • View Profile
Arch Linux, SFML2, Drawing sprites through static class
« Reply #2 on: December 12, 2010, 03:40:37 pm »
Quote from: "Laurent"

What kind of artifacts?


Sorry, don't have any image editor with me right now to crop it.

Quote from: "Laurent"
A global/static pointer to a sf::RenderWindow which is allocated in CWindow::Init?

Doesn't change anything.  Still the same as above.

Quote from: "Laurent"
What happens if you create the image and sprite after calling CWindow::Init? ...

Woah! Now it works as it should for some reason! Never fought that window is interconnected with Image :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Arch Linux, SFML2, Drawing sprites through static class
« Reply #3 on: December 12, 2010, 05:18:10 pm »
Quote
Woah! Now it works as it should for some reason! Never fought that window is interconnected with Image

Any graphics call that uses OpenGL needs a valid OpenGL context to be created and active. And this is done when creating a window.
However, this is not supposed to happen in SFML 1.6, there is always a valid context even when there's no window. Weird...
Laurent Gomila - SFML developer

ritave

  • Newbie
  • *
  • Posts: 26
    • View Profile
Arch Linux, SFML2, Drawing sprites through static class
« Reply #4 on: December 12, 2010, 06:03:08 pm »
Look back at the topic name - it's SFML2 ;)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Arch Linux, SFML2, Drawing sprites through static class
« Reply #5 on: December 12, 2010, 06:41:58 pm »
Oops... So this is definitely not supposed to happen.

Can you try creating a sf::Context instance at the beginning of your main(), and see if the bug is still there?
Laurent Gomila - SFML developer

ritave

  • Newbie
  • *
  • Posts: 26
    • View Profile
Arch Linux, SFML2, Drawing sprites through static class
« Reply #6 on: December 12, 2010, 06:56:03 pm »
After adding sf::Context Conext at the top of main() function of the minimal example, the problem still persists.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Arch Linux, SFML2, Drawing sprites through static class
« Reply #7 on: December 12, 2010, 08:42:21 pm »
What graphics drivers do you use? Are they up-to-date?
Laurent Gomila - SFML developer

ritave

  • Newbie
  • *
  • Posts: 26
    • View Profile
Arch Linux, SFML2, Drawing sprites through static class
« Reply #8 on: December 12, 2010, 08:53:35 pm »
I have intel integrated 945gme so it's: i915 (checked in lsmod)
I update my system daily, which means the drivers too, and they are from Arches depos, so they're probably the stable ones.

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Arch Linux, SFML2, Drawing sprites through static class
« Reply #9 on: December 13, 2010, 02:28:33 am »
I'm on Arch and that corruption is usually caused by a lost GL context or loaded images in a thread (which results in a lost GL context). I wouldn't really rely on Intel graphics drivers as a benchmark for compatibility.

 

anything