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

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - arash28134

Pages: [1]
1
Graphics / SFML Unable to open file error on Arch Linux
« on: August 15, 2023, 02:48:27 pm »
Hi. I'm using Arch with Nvidia's latest stable driver.
This is my code:

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

#include <iostream>

using namespace sf;

int main(){
    RenderWindow window(VideoMode(800, 600), "Flappy Bird");
    std::cout << "\nWindow created.\n";

    std::cout << "\nCreating texture...\n";
    Texture texture;
    if (!texture.loadFromFile("/assets/textures/image.jpg"))
        std::cout << "\nFailed loading texture.\n";
        return EXIT_FAILURE;
    Sprite sprite(texture);
    std::cout << "\nTexture created.\n";

    std::cout << "\nCreating font...\n";
    Font font;
    if (!font.loadFromFile("assets/fonts/arial.ttf"))
        std::cout << "\nFailed loading font.\n";
        return EXIT_FAILURE;
    Text text("Hello SFML world!", font, 50);

    std::cout << "\nFont created.\n";

    std::cout << "\nCreating music...\n";
    Music music;
    if (!music.openFromFile("assets/sounds/background.mp3"))
        std::cout << "\nFailed loading music.\n";
        return EXIT_FAILURE;
    std::cout << "\nMusic created...\n";
   
    music.play();

    while (window.isOpen())
    {
        Event event;
        while (window.pollEvent(event))
        {
            switch (event.type)
            {
            case Event::Closed:
                window.close();
                break;
           
            default:
                break;
            }
        }

        window.clear();

        window.draw(sprite);

        window.draw(text);

        window.display();
    }
   
    // Exit the program successfully...
    return EXIT_SUCCESS;
}
 

When I run this, I get the following output:

Quote
Window created.
Creating texture...
Failed to load image "/assets/textures/image.jpg". Reason: Unable to open file


Failed loading texture.

Any ideas?  :-\
p.s.: This is my first time posting here, sorry if the formatting is trash.

Pages: [1]
anything