SFML community forums

Help => General => Topic started by: Deuterium on August 12, 2012, 05:05:28 am

Title: documentation example not working for me
Post by: Deuterium on August 12, 2012, 05:05:28 am
hello I was using the documentation example as a template just to see how to set things up and when I used the font part only and compiled and debugged it open into a white screen and then shut down automatically. I changed the font, made sure the font name was right and put the font in the exe folder but same results. I also tried to display my own image using the sprite but white screen and automatically exit out. What am I doing wrong?

thanks
Title: Re: documentation example not working for me
Post by: kaB00M on August 12, 2012, 05:31:34 am
Show some code.
Title: Re: documentation example not working for me
Post by: Deuterium on August 12, 2012, 05:43:02 am
yeah um i did I think i posted an image put that obviously did not show up.....
 code:
#include <SFML/Graphics.hpp>

int main()
{
    sf::RenderWindow window(sf::VideoMode(300, 200), "SFML works!");
    // Create a graphical text to display
    sf::Font font;
    if (!font.loadFromFile("arial.ttf"))
        return EXIT_FAILURE;
    sf::Text text("Hello SFML", font, 50);

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(text);
        window.display();
    }

    return EXIT_SUCCESS;
}

[attachment deleted by admin]
Title: Re: documentation example not working for me
Post by: kaB00M on August 12, 2012, 07:34:00 am
You have to place the font in the same folder AS THE PROJECT FILES.

Title: Re: documentation example not working for me
Post by: Deuterium on August 12, 2012, 07:49:14 am
thanks! the font now works! is it the same with any other media type files such as images? because images don't seem to be working for me.... 
Title: Re: documentation example not working for me
Post by: kaB00M on August 12, 2012, 08:10:41 am
Glad to help.  :)
What version are you using?
It should be the same for images.

http://www.sfml-dev.org/logo/sfml-big.png (http://www.sfml-dev.org/logo/sfml-big.png)

Try this in 2.0

int main()
{
    sf::RenderWindow window(sf::VideoMode(300, 200), "SFML works!");
    // Create a graphical text to display

    sf::Texture texture;
    if (!texture.loadFromFile("sfml-big.png"))
        return EXIT_FAILURE;
    sf::Sprite sprite(texture);


    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        window.draw(sprite);
        window.display();
    }

    return EXIT_SUCCESS;
}
 

Title: Re: documentation example not working for me
Post by: Deuterium on August 12, 2012, 08:35:40 am
It worked! thanks again! I have found the problem. It doesnt seem to like my jpeg image for some reason...


 ;D
Title: Re: documentation example not working for me
Post by: kaB00M on August 12, 2012, 07:20:12 pm
Quote
The supported image formats are bmp, png, tga, jpg, gif, psd, hdr and pic. Some format options are not supported, like progressive jpeg. If this function fails, the image is left unchanged.

http://www.sfml-dev.org/documentation/2.0/classsf_1_1Image.php#a9e4f2aa8e36d0cabde5ed5a4ef80290b (http://www.sfml-dev.org/documentation/2.0/classsf_1_1Image.php#a9e4f2aa8e36d0cabde5ed5a4ef80290b)

 :)