SFML community forums

Help => Graphics => Topic started by: smguyk on December 15, 2014, 05:45:19 am

Title: sf::Shader as member variable and accessing it using a reference &
Post by: smguyk on December 15, 2014, 05:45:19 am
For my game, I have a resources class that holds all the textures, fonts, etc. and I can access them like so:
resources->getTexture("player")
which would return a reference to the player texture.

The function is
sf::Texture &getTexture(const std::string &name)

This all works fine. Now I'd like to also add all my shaders to the resources class.

Naturally I created this function
sf::Shader &getShader(const std::string &name)
which would return a reference to the shader, but the compile time error is

Code: [Select]
error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'
I really want to have all my resources in one place, so if I could somehow make this work and put all the shaders in my resources class it'd be really great.

I don't know what to do
Title: Re: sf::Shader as member variable and accessing it using a reference &
Post by: smguyk on December 15, 2014, 07:10:42 am
I solved it. I changed the function to

std::unique_ptr<sf::Shader> Resources::shaderBlur() {
  auto shader = std::unique_ptr<sf::Shader>(new sf::Shader());
  shader->loadFromFile("blur.frag", sf::Shader::Type::Fragment);
  return shader;
}

and use the shader with

auto shader = resources->shaderBlur();