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.


Messages - arash28134

Pages: [1]
1
General / Re: Android build error on launch
« on: August 16, 2023, 08:52:26 am »
First error suggests an issue with EGL initialization. make sure that you're initializing EGL properly before using it.

2
Graphics / Re: SFML Unable to open file error on Arch Linux
« on: August 15, 2023, 06:39:59 pm »
Note that this code is wrong:

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

without indentation it means:

    if (!texture.loadFromFile("/assets/textures/image.jpg"))
        std::cout << "\nFailed loading texture.\n";

    return EXIT_FAILURE;

So it would also just exit your application.
I'm personally a fan of using curly braces at all times, even or especially for single line statements:

    if (!texture.loadFromFile("/assets/textures/image.jpg"))
    {
        std::cout << "\nFailed loading texture.\n";
        return EXIT_FAILURE;
    }

Note the same issue for the music

Yes! this fixed my issue; thanks. it's weird how I had never noticed this in C++, I guess because I also usually go with curly braces.

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

3
Graphics / Re: SFML Unable to open file error on Arch Linux
« on: August 15, 2023, 05:28:09 pm »
You most likely don't want to use /assets as this will look for a folder in the root directory of you system called assets. For a relative path, you can just use assets/textures/image.jpg.

Then make sure the assets directory in your working directory.

p.s.: This is my first time posting here, sorry if the formatting is trash.
You can use the [code=cpp][/code] tags for code formatting.

Changing /assets to assets doesn't make any difference, except it now doesn't even output an error for some reason.
this is the output:

Quote
Window created.

Creating texture...
%

What does that "%" at the end even mean?

4
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