0

I have a sprite class which uses an SDL_Texture over an SDL_Surface in lieu of perfomance. The class looks something like this:

class Sprite
{
    public:
        ...

    private:
        SDL_Texture *m_texture;
        SDL_Rect m_blitRect;

        int m_x;
        int m_y;
};

Now the problem is when creating an SDL_Texture you also need an SDL_Renderer object as well as an SDL_Surface to create it. Normally this would look something like this:

SDL_Texture *texture = SDL_CreateTextureFromSurface(renderer, surface);

The SDL surface can be created and disposed of while creating the texture however, the problem is, I want to be able to have a rendering object that isn't global. I want a decoupled framework and I don't know how to achieve that in this instance. My first thought was to make a renderer class and have it as a constructor argument but that cannot happen as it would complicate things down the road and cannot be an option. Are there any other ways to decouple the two?

Martin G
  • 17,357
  • 9
  • 82
  • 98
Semirix
  • 271
  • 3
  • 13

1 Answers1

1

If you want to decouple your Texture from the renderer and surface parameter, I think your best best is to actually delay the call to the SDL_CreateTextureFromSurface until you actually get these arguments.

That way, your Texture texture constructor will not use/need these arguments.

Ven
  • 19,015
  • 2
  • 41
  • 61