SFML community forums

Help => Window => Topic started by: silver108 on August 11, 2016, 12:56:28 pm

Title: Trying to return a renderwindow
Post by: silver108 on August 11, 2016, 12:56:28 pm
So for my game, I was coding a basic rendering manager to manage
drawing the window and displaying things. But when I try to return a window in one of my
functions i get an error similar to this
Quote
   function "sf::RenderWindow::RenderWindow(const sf::RenderWindow &)" (declared implicitly) cannot be referenced -- it is a deleted function
Here is my (minimal error producing) code:
#include "stdafx.h"
#include "RenderManager.h"



RenderManager::RenderManager()
{
}

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

RenderManager::~RenderManager()
{
}
I hope I posted everything right, as it is my first time
Title: Re: Trying to return a renderwindow
Post by: Mr_Blame on August 11, 2016, 01:39:16 pm
Dude, sf::RenderSystem is a non copyable class you should return a pointer to allocated window.
Title: Re: Trying to return a renderwindow
Post by: Laurent on August 11, 2016, 01:58:22 pm
Writing a function that instanciates a window and returns it is not a good idea. Either the window is managed entirely by the RenderManager and then it should be kept hidden inside it, or the window is used outside and then you'd better create it in your main (or whatever you have on top of all that stuff) and pass a reference to it to the RenderManager functions that need it.
Title: Re: Trying to return a renderwindow
Post by: silver108 on August 11, 2016, 02:30:11 pm
Oh, thanks both of you very much.
Also, Laurent out of the two methods you suggested are there
any pros or cons to each one?
Title: Re: Trying to return a renderwindow
Post by: Laurent on August 11, 2016, 03:25:20 pm
Quote
Also, Laurent out of the two methods you suggested are there
any pros or cons to each one?
It depends if RenderManager is intended to provide a complete wrapper to sf::RenderWindow, or just use it.
Title: Re: Trying to return a renderwindow
Post by: silver108 on August 11, 2016, 04:24:35 pm
One last thing,
are there any documentation pages or forum posts
about handling rendering completely inside the engine
Title: Re: Trying to return a renderwindow
Post by: Laurent on August 11, 2016, 08:34:28 pm
It depends what you mean with "handling rendering completely inside the engine" ;)
Title: Re: Trying to return a renderwindow
Post by: silver108 on August 12, 2016, 12:45:06 pm
I mean like the way you said
Quote
the window is managed entirely by the RenderManager and then it should be kept hidden inside it
Sorry if i worded it wrong
Title: Re: Trying to return a renderwindow
Post by: Laurent on August 12, 2016, 02:37:23 pm
Ok, it's clear. Why do you think it would be so much different to manage the window & rendering inside a class? And compared to... what? doing everything in main()?