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 - dimoooooch

Pages: [1]
1
General / Re: Failed to load image
« on: March 11, 2024, 07:23:52 am »
Do you run the program directly or through IDE? Usually, IDE has working space and could be different than where you have exe files.

i run it using Visual Studio 2019 debug

2
General / Failed to load image
« on: March 11, 2024, 07:09:30 am »
hello guys, i have another problem. here's my code:

#include <SFML/Graphics.hpp>
#include <iostream>
using namespace sf;
using namespace std;

int main()
{
    RenderWindow window(VideoMode::getFullscreenModes()[0], "Chess Fantasy", Style::Fullscreen);
    Texture board, wr, wp;
    if (!board.loadFromFile("board.png") ||
        !wr.loadFromFile("wr.png") ||
        !wp.loadFromFile("wp.png"));
    {
        cerr << "Failed to load textures." << endl;
        return 1;
    }

    float centerX = window.getSize().x / 2.0f;
    float centerY = window.getSize().y / 2.0f;

    RectangleShape board1(Vector2f(800, 800));
    board1.setTexture(&board);
    RectangleShape wr1(Vector2f(100, 100));
    wr1.setTexture(&wr);
    board1.setPosition(centerX - board1.getLocalBounds().width / 2, centerY - 400);
    wr1.setPosition(centerX - board1.getLocalBounds().width / 2, centerY + 300);
    RectangleShape wp1(Vector2f(100, 100));
    wp1.setTexture(&wp);
    wp1.setPosition(centerX - board1.getLocalBounds().width / 2, centerY + 200);


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

        window.clear();
        window.draw(board1);
        window.draw(wr1);
        window.draw(wp1);
        window.display();
    }

}

in my project's folder and debug folder i have board.png, wr.png, wp.png. but without any reason, it says "Failed to load textures." Other people have a reason, but i don't. also, i tried to insert the path to the file, but then it said "Failed to load textures. Reason: Unable to open file."

so, how do i fix that?

3
Hello. I was working on my project and when i made a thread that would clean the window from all the objects (buttons and background) the c++ part was working, but sfml part wasn't. After i pressed "Chess" button it gave me this text:

Chess button pressed!
smth
Failed to activate OpenGL context:   .
Failed to activate the window's context

Here's my code:

#include <SFML/Graphics.hpp>
#include <iostream>
using namespace sf;
using namespace std;

RenderWindow window(VideoMode::getFullscreenModes()[0], "Chess Fantasy", Style::Fullscreen);

void thread1()
{
    cout << "smth" << endl;
    window.clear();
}

Thread chessThread(&thread1);

int main()
{
   

    Texture texture1, texturebg;
    if (!texture1.loadFromFile("texture1.png") ||
        !texturebg.loadFromFile("texturebg.png"))
    {
        cerr << "Failed to load textures." << endl;
        return 1;
    }

    RectangleShape chessButton(Vector2f(800, 200)); // Прямоугольник для кнопки Chess
    chessButton.setTexture(&texture1);
    chessButton.setOutlineThickness(5);
    chessButton.setOutlineColor(Color(255, 255, 255));
    RectangleShape mazeButton(Vector2f(800, 200)); // Прямоугольник для кнопки Maze
    mazeButton.setTexture(&texture1);
    mazeButton.setOutlineThickness(5);
    mazeButton.setOutlineColor(Color(255, 255, 255));
    RectangleShape quitButton(Vector2f(800, 200)); // Прямоугольник для кнопки Quit
    quitButton.setTexture(&texture1);
    quitButton.setOutlineThickness(5);
    quitButton.setOutlineColor(Color(255, 255, 255));
    RectangleShape background(Vector2f(window.getSize().x, window.getSize().y)); // Прямоугольник для фона
    background.setTexture(&texturebg);

    Font font;
    if (!font.loadFromFile("arial.ttf"))
    {
        cerr << "Failed to load font." <<  endl;
        return 1;
    }

    Text chessText("Chess", font, 72);
    Text mazeText("Maze", font, 72);

    // Уточненные позиции текстов и кнопок для точного выравнивания
    float centerX = window.getSize().x / 2.0f;
    float centerY = window.getSize().y / 2.0f;

    chessText.setPosition(centerX - chessText.getLocalBounds().width / 2, centerY - 300);
    chessButton.setPosition(centerX - chessButton.getLocalBounds().width / 2, centerY - 350);

    mazeText.setPosition(centerX - mazeText.getLocalBounds().width / 2, centerY - 50);
    mazeButton.setPosition(centerX - mazeButton.getLocalBounds().width / 2, centerY - 100);

    Text quitText("Quit", font, 72);
    quitText.setPosition(centerX - quitText.getLocalBounds().width / 2, centerY + 200);
    quitButton.setPosition(centerX - quitButton.getLocalBounds().width / 2, centerY + 150);

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

            if (event.type == Event::MouseButtonPressed)
            {
                if (event.mouseButton.button == Mouse::Left)
                {
                    if (chessButton.getGlobalBounds().contains(event.mouseButton.x, event.mouseButton.y))
                    {
                        cout << "Chess button pressed!" << endl;

                        chessThread.launch();
                    }
                    else if (mazeButton.getGlobalBounds().contains(event.mouseButton.x, event.mouseButton.y))
                    {
                        cout << "Maze button pressed!" << endl;
                    }
                    else if (quitButton.getGlobalBounds().contains(event.mouseButton.x, event.mouseButton.y))
                    {
                        window.close();
                    }
                }
            }
        }

        window.draw(background);
        window.draw(chessButton);
        window.draw(chessText);
        window.draw(mazeButton);
        window.draw(mazeText);
        window.draw(quitButton);
        window.draw(quitText);
        window.display();
    }

   

    return 0;
}


4
System / Re: what do I need to fully use the library of SFML?
« on: December 14, 2023, 07:40:07 am »
First, it depends on which environment you are developing. w.g. Windows/Linux/Mac? Visual Studio/MinGW?

There are some tutorials that should guide you through setting it up (in these environments, look for the "SFML and ..."), here:
https://www.sfml-dev.org/tutorials/2.6/

Also depending on your environment is which types of files you need and where to put them.

If you are specific problems with those tutorials, you can give more information about your environment and which problems you are encountering. :)

my problem is when i was setting it up (Win 10, Visual Studio 2019), i did the same as it was showed on the site but console still had some errors, for example MSB6006 on line 1074 that i dont even have. i only have 38 lines

5
System / what do I need to fully use the library of SFML?
« on: December 04, 2023, 07:49:29 am »
first of all, when I downloaded this library, what and where do I need to put to use it?

Pages: [1]
anything