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

Author Topic: sf::Shader as member variable and accessing it using a reference &  (Read 1300 times)

0 Members and 1 Guest are viewing this topic.

smguyk

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
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

smguyk

  • Jr. Member
  • **
  • Posts: 79
    • View Profile
Re: sf::Shader as member variable and accessing it using a reference &
« Reply #1 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();

 

anything