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

Author Topic: Cannot create an image from scratch.  (Read 1106 times)

0 Members and 1 Guest are viewing this topic.

tehnugget

  • Newbie
  • *
  • Posts: 2
    • View Profile
Cannot create an image from scratch.
« on: September 12, 2012, 06:26:07 am »
I appear to have run into an error within SFML 2.0. From the example given in the documentation, I cannot create an image based on the code given.

Here is my main.cpp.

#include <SFML/Graphics.hpp>


#define spritewidth 32
#define spriteheight 32

int main()
{


    sf::RenderWindow Window(sf::VideoMode(800, 600, 32), "SFML woo");

    sf::Image spritesheet;
    if (!spritesheet.loadFromFile("spritesheet.png"))
        return -1;


    sf::Image image;
    if (!image.create(20, 20, sf::Color(0, 0, 0, 255)))
        return -1;

    while (Window.isOpen())
    {

            sf::Event Event;
            while (Window.pollEvent(Event))
            {
                switch (Event.type)
                {
                    case sf::Event::Closed:
                        Window.close();
                        break;
                    default:
                        break;

                }
            }
            Window.clear(sf::Color(255, 255, 255));
            Window.display();
    }
    return 0;
}
 

Compiling with the GNU/GCC/MinGW compiler base, running sfml 2.0 rc.

Here is my compiler error.
In function 'int main()':
error: could not convert 'image.sf::Image::create(20u, 20u, (*(const sf::Color*)(& sf::Color(0, 0, 0, 255))))' from 'void' to 'bool'
error: in argument to unary !
=== Build finished: 2 errors, 0 warnings ===
 

Searching led me nowhere, I only seemed to run into dead-ends, as apparently no-one has suffered the same problem I have!

Thank you!

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Cannot create an image from scratch.
« Reply #1 on: September 12, 2012, 07:56:44 am »
What about reading the documentation? ::)
Image::create doesn't return a bool (it can't fail).
Laurent Gomila - SFML developer

tehnugget

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Cannot create an image from scratch.
« Reply #2 on: September 13, 2012, 01:17:06 pm »
That's funny, I did try without it, but some some reason it crashed. I tried again now, and poof! It worked!

Thank you, Laurent!

 

anything