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:
When I run this, I get the following output:
Any ideas?
p.s.: This is my first time posting here, sorry if the formatting is trash.
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;
}
#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?
![Undecided :-\](https://www.sfml-dev.org/forums/Smileys/default/undecided.gif)
p.s.: This is my first time posting here, sorry if the formatting is trash.