Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Trying to return a renderwindow  (Read 4875 times)

0 Members and 1 Guest are viewing this topic.

silver108

  • Newbie
  • *
  • Posts: 4
    • View Profile
Trying to return a renderwindow
« 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
« Last Edit: August 11, 2016, 12:59:28 pm by silver108 »

Mr_Blame

  • Full Member
  • ***
  • Posts: 192
    • View Profile
    • Email
Re: Trying to return a renderwindow
« Reply #1 on: August 11, 2016, 01:39:16 pm »
Dude, sf::RenderSystem is a non copyable class you should return a pointer to allocated window.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Trying to return a renderwindow
« Reply #2 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.
Laurent Gomila - SFML developer

silver108

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Trying to return a renderwindow
« Reply #3 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?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Trying to return a renderwindow
« Reply #4 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.
Laurent Gomila - SFML developer

silver108

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Trying to return a renderwindow
« Reply #5 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Trying to return a renderwindow
« Reply #6 on: August 11, 2016, 08:34:28 pm »
It depends what you mean with "handling rendering completely inside the engine" ;)
Laurent Gomila - SFML developer

silver108

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Trying to return a renderwindow
« Reply #7 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Trying to return a renderwindow
« Reply #8 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()?
Laurent Gomila - SFML developer

 

anything