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

Author Topic: documentation example not working for me  (Read 2281 times)

0 Members and 2 Guests are viewing this topic.

Deuterium

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
documentation example not working for me
« 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

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: documentation example not working for me
« Reply #1 on: August 12, 2012, 05:31:34 am »
Show some code.



Deuterium

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: documentation example not working for me
« Reply #2 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]

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: documentation example not working for me
« Reply #3 on: August 12, 2012, 07:34:00 am »
You have to place the font in the same folder AS THE PROJECT FILES.




Deuterium

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: documentation example not working for me
« Reply #4 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.... 

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: documentation example not working for me
« Reply #5 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

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;
}
 

« Last Edit: August 12, 2012, 08:21:18 am by kaB00M »



Deuterium

  • Newbie
  • *
  • Posts: 4
    • View Profile
    • Email
Re: documentation example not working for me
« Reply #6 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

kaB00M

  • Full Member
  • ***
  • Posts: 101
    • View Profile
    • Caffeware
    • Email
Re: documentation example not working for me
« Reply #7 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

 :)