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
Window / Re: Project with responsive window for different resolutions
« on: September 15, 2021, 06:12:54 pm »
Thank you for your response! I will try to implement this feature according to that tutorial.

2
Window / Project with responsive window for different resolutions
« on: September 09, 2021, 11:00:13 pm »
Hello!

I have developed a cross-platform project using SFML and CMake for macOS, Ubuntu, and Windows. Everything works fine so far, but I have tested this project on three different laptops for each OS stated above and the resolution differs.

I have set the window's resolution of the project to 1280x800. On my mac and on my windows laptop everything is fine as the maximum resolution is above 1280x800... But I have a laptop that is running Ubuntu and which has a maximum resolution of 1366x768 and here, it seems that the objects (rectangles and a grid) are "misplaced" because of the resolution.

My question is how can I make this window responsive? Where should I start? Is it even possible?

Kind regards,

Daniel

3
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! :)

4
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...

5
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;
}

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

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

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

9
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?

10
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!

11
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]