SFML community forums
Help => Graphics => Topic started by: ritave 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:
#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();
}
}
-
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.
Here's the download to minimal example which has a png and somewhat minimal code.
Works for me on Windows.
-
What kind of artifacts?
(http://i54.tinypic.com/2ccrlep.png)
Sorry, don't have any image editor with me right now to crop it.
A global/static pointer to a sf::RenderWindow which is allocated in CWindow::Init?
Doesn't change anything. Still the same as above.
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
-
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...
-
Look back at the topic name - it's SFML2 ;)
-
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?
-
After adding sf::Context Conext at the top of main() function of the minimal example, the problem still persists.
-
What graphics drivers do you use? Are they up-to-date?
-
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.
-
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.