Hello there!
I'm trying to use sf::RenderImage with the latest SFML2 version from git.
Here's my code:
#include <iostream>
#include <SFML/Graphics.hpp>
#include <sstream>
// #include "board.h"
int main(int argc, char **argv)
{
sf::RenderWindow App(sf::VideoMode(400, 400), "Test", sf::Style::Close);
App.SetFramerateLimit(100);
sf::Image img;
sf::Sprite sprite;
sf::RenderImage r_img;
if(!img.LoadFromFile("welcome.png")) //An ordinary image
{
std::cout<<"Error"<<std::endl;
return -1;
}
sprite.SetImage(img); //Sprite of the above image
sprite.SetPosition(0.f, 0.f);
if(!r_img.Create(App.GetWidth(), App.GetHeight())) //Create the renderimage
{
std::cout<<"Error"<<std::endl;
return -1;
}
r_img.Clear(sf::Color::White); //White background
r_img.Draw(sprite); //Draw the above sprite to the renderimage
sprite.SetPosition(100.f, 100.f); //Move the sprite
r_img.Draw(sprite); //Draw same sprite to different position
sf::Sprite mySprite(r_img.GetImage(), sf::Vector2f(0,0)); //The sprite of the renderimage-image
while(App.IsOpened())
{
sf::Event Event;
while(App.PollEvent(Event))
{
if(Event.Type == sf::Event::Closed)
App.Close();
}
App.Clear(sf::Color::Green);
App.Draw(mySprite);
App.Display();
}
return 0;
}
This code results in the opening of a window which is immediately closed.
I've been playing around with trying to draw images (sprites) and shapes to a RenderImage and then display it like this, but it has either resulted in a complete lock-up or that the application exits (no errors or anything).
I'm using an up-to-date version of Archlinux 64-bit, Intel GMA4500 with latest drivers.
glxgears runs perfectly with ~60fps (due to VSync)
Now.. Have I completely missed the purpose of sf::RenderImage, am I doing something wrong or is there something wrong with other software (like drivers or Xorg)?
Also, there seems to be no sf::RenderImage::IsAvailable()