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

Author Topic: Image not loading.  (Read 1186 times)

0 Members and 1 Guest are viewing this topic.

Ludvins

  • Newbie
  • *
  • Posts: 1
    • View Profile
Image not loading.
« on: February 06, 2016, 07:34:25 pm »
Can someone help me with this code, i dont know why it isnt showing the image, i just get a black screen.
It seems like a .dll issue but im not sure.
Thx. ;D

#include <SFML/Graphics.hpp>

int main()
{
        sf::RenderWindow window(sf::VideoMode(640, 360), "Space invaders");
        sf::Texture backgroundTexture;
        backgroundTexture.loadFromFile("original.jpg");
        sf::Sprite backgroundSprite;
        backgroundSprite.setTexture(backgroundTexture);

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

                window.clear();
                window.draw(backgroundSprite);
                window.display();

        }

        return 0;
}
« Last Edit: February 09, 2016, 10:16:32 am by eXpl0it3r »

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Image not loading.
« Reply #1 on: February 06, 2016, 09:02:50 pm »
Please post code inside code tags, thus:
[code=cpp]bool isTrue = true;[/code]
becomes:
bool isTrue = true;

If the texture isn't loading, the sprite will display nothing but will not complain about doing so so you need to check the texture loading success for yourself before continuing with the program. Instead of just attempting to load the file, test its return value thusly:
if (!backgroundTexture.loadFromFile("original.jpg"))
    return EXIT_FAILURE;
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Image not loading.
« Reply #2 on: February 12, 2016, 03:48:42 pm »
Maybe your image is not in needed directory or you launched you code from IDE. When you launch your code from IDE it makes the app working dir a project dir instead of exe file dir.