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

Pages: [1]
1
General / Re: Cross-platform project with CMake and SFML
« on: January 03, 2021, 05:16:19 pm »
I was using the wrong version of MinGW :)) That's fixed now. Thank you for your tips! :)

2
General / Cross-platform project with CMake and SFML
« on: December 18, 2020, 07:22:22 pm »
Hello!

I am trying to make a cross-platform project with CMake and SFML.

The project works fine if I build it for Visual Studio 2019 32bit because I have SFML for 32bit.

I also want to build the project using MinGW makefiles on windows with Git bash and on Linux as well.

My problem is that when I build the project using MinGW64 on Windows or Linux I get a bunch of warnings when the object files are built and some errors at the end when linking happens (See below).

I have provided the output when trying to build the project using MinGW and the CMakeLists.txt
I used the following script when building on git:
mkdir build
cd build
cmake .. -G "MinGW Makefiles"
make

How can I compile the project using MinGW makefiles?
How to make a proper CMakeLists for cross-platform?
How to build the project properly?

Update*
I modified the cmakelists just a bit, but it still doesn't make a big differenece...

3
General / Implementing Insertion Sort Algorithm
« on: August 07, 2020, 12:53:08 am »
Hello! I'm trying to implement insertion sort algorithm using iterators. So... In the source code, I have a vector of rectangles which will be sorted by their heights. I've printed the heights values which were in the correct order but when I'm trying to change the x, y coordinates it doesn't seem to work.

If you can play around with the code and maybe figure out something, please let me know... Thanks! :D

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

int main()
{
    sf::RenderWindow window(sf::VideoMode(1280, 800), "SFML works!");
   
        std::vector<sf::RectangleShape> sequence;
        int els = 5;
        int max = 100;
        int min = 10;
       
        float randomHeight;
        float xCurrPos = 100;

        for (unsigned int i = 0; i < els; i++)
        {
                randomHeight = rand() % max + min;
                sf::RectangleShape unit;
                unit.setSize(sf::Vector2f(4, randomHeight));
                unit.setFillColor(sf::Color::Black);
                unit.setRotation(180);
                unit.setPosition(xCurrPos, 720);
                xCurrPos += 10;
                sequence.push_back(unit);
        }


        while (window.isOpen())
        {
                std::vector<sf::RectangleShape>::iterator iti;
                int j;
                sf::RectangleShape leftmost;
                float xs, ys, xl, yl;

                for (iti = sequence.begin() + 1; iti != sequence.end(); ++iti)
                {
                        j = std::distance(sequence.begin(), std::prev(iti));
                        leftmost = *iti;

                        while (j >= 0 && sequence.at(j).getSize().y > leftmost.getSize().y)
                        {
                                sequence.at(j + 1) = sequence.at(j);
                                xs = sequence.at(j + 1).getPosition().x;
                                ys = sequence.at(j + 1).getPosition().y;
                                sequence.at(j).setPosition(sf::Vector2f(xs, ys));
                                --j;
                        }
                        sequence.at(j + 1) = leftmost;
                        xl = sequence.at(j + 1).getPosition().x;
                        yl = sequence.at(j + 1).getPosition().y;
                        leftmost.setPosition(sf::Vector2f(xl, yl));
                }
                       
               
                // prints the sorted sequence
                window.clear(sf::Color::White);
                for (std::vector<sf::RectangleShape>::iterator itp = sequence.begin(); itp != sequence.end(); itp = std::next(itp))
                {
                        window.draw(*itp);
                        //std::cout << (*itp).getSize().y << "\n";
                }
                window.display();
        }
    return 0;
}

4
General / Re: Sorting a vector of rectangles
« on: July 13, 2020, 05:01:17 pm »
Yeah... I found out that later. Thanks!

5
General / Sorting a vector of rectangles
« on: July 13, 2020, 11:38:55 am »
Hello!

So I'm trying to implement bubble sort algorithm. I've created a vector in which I'm appending some rectangles and I'll sort them by their heights but it doesn't seem to sort anything. Am I doing something wrong? Please test this code... it's not too much.

#include <SFML/Graphics.hpp>
#include <ctime>
#include <iostream>
#include <vector>

int main()
{
    srand(time(0));
    float randomHeight;
    std::vector<sf::RectangleShape> v;
    float currY = 100;
    sf::RenderWindow window(sf::VideoMode(1280, 800), "SFML works!");
   
    for (unsigned int i = 0; i < 100; i++)
    {
       
        randomHeight = rand() % 500 + 200;
        sf::RectangleShape rect({ 4, randomHeight });
        rect.setFillColor(sf::Color::White);
        rect.setRotation(180);
        currY += 10;
        rect.setPosition({ currY, 720 });

        v.push_back(rect);
    }
 

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
        }
       
       
       
        for (unsigned int i = 0; i < v.size(); i++)
        {
            for (auto itj = v.begin(); itj != v.end() - 1; itj = std::next(itj))
            {
                if ((*itj).getSize().y > (*std::next(itj)).getSize().y)
                {
                    std::swap(*itj, *std::next(itj));
                }
            }
        }

        for (auto i = v.begin(); i != v.end(); i = std::next(i))
            window.draw(*i);
        window.display();
       
       
    }
   
    return 0;
}

6
General / Re: How to delay the process of drawing
« on: July 10, 2020, 12:21:46 am »
Cool! Thanks for your answer :D

7
General / How to delay the process of drawing
« on: July 06, 2020, 12:52:17 am »
Hello! I've created an interface in which I am drawing some lines on the window. My question is how can I slow down this process of drawing (like printing them one by one in real time)? Would ctime / chrono libraries be useful or is there something else that you can do with SFML?

8
General / Re: sf::PrimitiveType is unscoped warning in VS 2k19
« on: June 25, 2020, 02:29:19 pm »
It makes sense now. Thanks for your answer!

9
General / sf::PrimitiveType is unscoped warning in VS 2k19
« on: June 25, 2020, 01:02:30 am »
Hello! I'm currently working on a personal project in Visual Studio 2019. I've created some 'buttons' for a menu and I decided that I want to put them in a container, such as a vector. My issue is that whenever I use this vector to display the buttons, I get this warning: "The enum type 'sf::PrimitiveType' is unscoped. Prefer 'enum class' over 'enum' (Enum.3).". It is not a big issue, but I'd like to get rid of this warning and know the meaning...

Also, I am working with classes... so I don't have everything in one file, I'll put here just the definitions of the main methods.


Interface::Interface()
{
        // A constructor where I am creating the buttons and then append them to a vector of type Button

        if (!font.loadFromFile("/AlgorithmSimulator/design/quicksandBold.otf"))
                std::cerr << "There's no such file" << std::endl;
       
        Button sortingAlgsB("Sorting Algorithms", sf::Color::Black, 15, sf::Color(224, 251, 252), { 200, 50 });
        sortingAlgsB.SetFont(font);
        sortingAlgsB.Positionate({ 100, 100 });

        Button pathAlgsB("Pathfinding Algorithms", sf::Color::Black, 15, sf::Color(224, 251, 252), { 200, 50 });
        pathAlgsB.SetFont(font);
        pathAlgsB.Positionate({ 100, 50 });



        buttons.push_back(sortingAlgsB);
        buttons.push_back(pathAlgsB);

       
        Init();
               
}

void Interface::Init()
{
        // Here's the method with the main loop

        sf::RenderWindow window(sf::VideoMode(1280, 800), "AlgorithmSimulator");
               
        while (window.isOpen())
        {
                sf::Event event;
                while (window.pollEvent(event))
                {
                        for (std::vector<Button>::iterator it = buttons.begin(); it != buttons.end(); it = std::next(it))
                        {
                                switch (event.type)
                                {
                                case sf::Event::Closed:
                                        window.close();
                                case sf::Event::MouseMoved:
                                        if ((*it).DetectMouse(window) == true)
                                        {
                                                (*it).SetTextColor(sf::Color(154, 3, 30));
                                        }
                                        else
                                        {
                                                (*it).SetTextColor(sf::Color::Black);
                                        }
                                        break;
                                case sf::Event::MouseButtonPressed:
                                        if ((*it).DetectMouse(window) == true)
                                        {
                                                (*it).SetTextColor(sf::Color::White);
                                                (*it).SetShapeColor(sf::Color(154, 3, 30));
                                        }
                                        break;
                                case sf::Event::MouseButtonReleased:
                                        if ((*it).DetectMouse(window) == true || (*it).DetectMouse(window) == false)
                                        {
                                                (*it).SetTextColor(sf::Color::Black);
                                                (*it).SetShapeColor(sf::Color(224, 251, 252));
                                        }
                                        break;
                                }
                        }
                }
                window.clear(sf::Color(224, 251, 252));
                for (std::vector<Button>::iterator it = buttons.begin(); it != buttons.end(); it = std::next(it))
                {
                        (*it).Draw(window);
                }
                //pathAlgsB.Draw(window);
                window.display();      
        }
}

Pages: [1]
anything