0
votes

I am creating a benchmark app to test speed of rendering images. I created two functions, one to return RenderWindow and one to use that RenderWindow for applying image there. When I call the second function, it gives me error: No matching constructor for initialisation of 'sf::RenderWindow'

Here are my functions:

sf::RenderWindow newWindow(int w, int h)
{
    sf::RenderWindow window;
    window.create(sf::VideoMode(w, h), "SFML Benchmark");
    return window;
}

void draw(int type, sf::RenderWindow dest) // 0 color small, 1 color big, 2 no color small, 3 no color big
{
    sf::Texture img;
    switch(type)
    {
        case 0: if(!img.loadFromFile("colorfull small.jpg")) cout << "Unable to laod image";
        case 1: if(!img.loadFromFile("colorfull big.jpg")) cout << "Unable to laod image";
        case 2: if(!img.loadFromFile("colorless small.jpg")) cout << "Unable to laod image";
        case 3: if(!img.loadFromFile("colorless big.jpg")) cout << "Unable to laod image";
    }
    sf::Sprite sprite;
    sprite.setTexture(img);
    dest.draw(sprite);
}

me calling the function in main:

draw(1, newWindow(600, 600));

Thank you.

1

1 Answers

1
votes

I don't think an sf::window is copyable.

Your function taking a window should look like this:

void draw(int type, sf::RenderWindow& dest)

Note the ampersand, wich denotes a reference instead of a copy.

Your function createing a window will need to return a pointer to the window. When I wrote it, I decided I'd not have a function for it but do it in main instead so I could use a local variable for the window.

Your drawing function should not create and load the texture and sprite. It will likely be called many times per second, you should create and load all your assets once and then draw the loaded assets as fast as the computer allows.