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

Author Topic: sf::RenderImage problem  (Read 3151 times)

0 Members and 1 Guest are viewing this topic.

xarxer

  • Newbie
  • *
  • Posts: 35
    • View Profile
sf::RenderImage problem
« on: June 22, 2011, 01:52:36 am »
Hello there!

I'm trying to use sf::RenderImage with the latest SFML2 version from git.
Here's my code:
Code: [Select]


#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()

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderImage problem
« Reply #1 on: June 22, 2011, 08:04:47 am »
Quote
This code results in the opening of a window which is immediately closed.

Are you sure that your application doesn't exit because of LoadFromFile or Create failing? If not, try to run it step by step with the debugger to see where it stops.
Laurent Gomila - SFML developer

xarxer

  • Newbie
  • *
  • Posts: 35
    • View Profile
sf::RenderImage problem
« Reply #2 on: June 22, 2011, 02:38:56 pm »
Here's a minimal example that reproduce the problem:

Code: [Select]


#include <iostream>
#include <SFML/Graphics.hpp>

int main(int argc, char **argv)
{
   
    sf::RenderWindow App(sf::VideoMode(400, 400), "Test", sf::Style::Close);
    App.SetFramerateLimit(100);

    sf::RenderImage r_img;
   
   
    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
   
    while(App.IsOpened())
    {
   sf::Event Event;
   while(App.PollEvent(Event))
   {
           if(Event.Type == sf::Event::Closed)
           App.Close();
   }

   App.Clear(sf::Color::Green);
   App.Display();
    }
   
   
    return 0;
}


If I comment out the line
Code: [Select]
 r_img.Clear(sf::Color::White); //White background
everything works (i.e I see a window with green background).
If it's executed as-is, I just see a window pop in and out of existence, and the return code form the app is 1.

This seems weird to me..

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderImage problem
« Reply #3 on: June 22, 2011, 03:02:56 pm »
That's probably a driver problem. I think I'll try to fix all the problems related to RenderImage in a future minor revision of SFML 2.
Laurent Gomila - SFML developer

xarxer

  • Newbie
  • *
  • Posts: 35
    • View Profile
sf::RenderImage problem
« Reply #4 on: June 22, 2011, 03:34:09 pm »
Hmm that's too bad..

What I'm trying to accomplish is to draw a sprite consisting of a white square onto a black background several times with different positions to get a board of white squares separated with black lines.
Do you have any ideas on how to accomplish this with minimal effort?

Thanks in advance!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
sf::RenderImage problem
« Reply #5 on: June 22, 2011, 04:02:14 pm »
This can be done easily with Image::Copy. Or even Image::SetPixel (if it's pure black and white).
Laurent Gomila - SFML developer