title: SDL render not working
body: <p>I have a problem creating this second class in my game, this is a class for player but when I call the texturemanager to draw the play, it's not working, but when i directly call the texturemanager to draw the player it was working. this is my class.</p>
  
  <p>Game.h</p>
  
  <pre><code>#pragma once
  
  #include &lt;SDL/SDL.h&gt;
  
  #include "TextureManager.h"
  #include "Player.h"
  
  class Game
  {
  public:
      Game(void);
      ~Game(void);
  
      void startGame();
      void init();
      void gameLoop();
      void eventHandler();
      void render();
      void exitGame();
  
  
  private:
      bool _isRunning;
  
      SDL_Window* _window;
      SDL_Renderer* _renderer;
  
      SDL_Rect _spriteClips[2];
  
      TextureManager _textureManager;
      Player _player;
  };
  </code></pre>
  
  <p>Game.cpp</p>
  
  <pre><code>#include "Game.h"
  #include "Error.h"
  
  Game::Game(void)
  {
      _window = nullptr;
      _isRunning = true;
  }
  
  
  Game::~Game(void)
  {
  }
  
  void Game::startGame()
  {
      init();
      gameLoop();
  }
  
  void Game::init()
  {
      if (SDL_Init(SDL_INIT_EVERYTHING) == 0)
      {
          _window = SDL_CreateWindow("Renderer", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
              640, 480, SDL_WINDOW_SHOWN);
  
          if (_window != nullptr)
          {
              _renderer = SDL_CreateRenderer(_window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
  
              if(_renderer!= nullptr)
              {
                  SDL_SetRenderDrawColor(_renderer, 255, 255, 255, 255);              
              }
              else
                  fatalError("Failed to create renderer");
          }
          else
              fatalError("Failed to create window!");
      }
      else
          fatalError("Failed to initialize SDL!");
  
      // temp image load
      _textureManager.loadFromFile("assets/tiles.png", _renderer);
  
      _spriteClips[0].x = 0;
      _spriteClips[0].y = 160;
      _spriteClips[0].w = 80;
      _spriteClips[0].h = 80;
  
      _spriteClips[1].x = 0;
      _spriteClips[1].y = 80;
      _spriteClips[1].w = 80;
      _spriteClips[1].h = 80;
  }
  
  void Game::gameLoop()
  {
      while (_isRunning != false)
      {
          eventHandler();
  
          render();
      }
  
      exitGame();
  }
  
  void Game::eventHandler()
  {
      SDL_Event evnt;
  
      while (SDL_PollEvent(&amp;evnt))
      {
          switch (evnt.type)
          {
          case SDL_QUIT:
              _isRunning = false;
              break;
          }
      }
  }
  
  void Game::render()
  {
      SDL_RenderClear(_renderer);
  
      _textureManager.draw(0, 0, &amp;_spriteClips[0], _renderer);
      _player.draw(200, 200, &amp;_spriteClips[1], _renderer);
  
      // when i used this, it is working
      //_textureManager.draw(200, 200, &amp;_spriteClips[1], _renderer);
  
      SDL_RenderPresent(_renderer);
  }
  
  void Game::exitGame()
  {
  
      SDL_DestroyRenderer(_renderer);
      SDL_DestroyWindow(_window);
      _window = nullptr;
      _renderer = nullptr;
  
      SDL_Quit();
  }
  </code></pre>
  
  <p>TextureManager.h</p>
  
  <pre><code>#pragma once
  
  #include &lt;SDL/SDL.h&gt;
  #include &lt;SDL/SDL_image.h&gt;
  #include &lt;string&gt;
  
  class TextureManager
  {
  public:
      TextureManager(void);
      ~TextureManager(void);
  
      bool loadFromFile(std::string filePath, SDL_Renderer* renderer);
      void free();
      void draw(int x, int y, SDL_Rect* clip, SDL_Renderer* renderer);
  
      int getWidth() { return _width; }
      int getHeight() { return _height; }
  
  private:
      SDL_Texture* _texture;
  
      int _width;
      int _height;
  };
  </code></pre>
  
  <p>TextureManager.cpp</p>
  
  <pre><code>#include "TextureManager.h"
  #include "Error.h"
  
  TextureManager::TextureManager(void)
  {
      _texture = nullptr;
      _width = 0;
      _height = 0;
  }
  
  
  TextureManager::~TextureManager(void)
  {
      free();
  }
  
  bool TextureManager::loadFromFile(std::string filePath , SDL_Renderer* renderer)
  {
      free();
  
      SDL_Texture* newTexture = nullptr;
      SDL_Surface* loadedSurface = IMG_Load(filePath.c_str());
  
      if(loadedSurface != nullptr)
      {
          SDL_SetColorKey(loadedSurface, SDL_TRUE, SDL_MapRGB(loadedSurface-&gt;format, 0, 0xFF, 0xFF));
          newTexture = SDL_CreateTextureFromSurface(renderer, loadedSurface);
  
          if(newTexture != nullptr)
          {
              _width = loadedSurface-&gt;w;
              _height = loadedSurface-&gt;h;
          }
          else
              fatalError("unable to create texture from surface!");
  
          SDL_FreeSurface(loadedSurface);
      }
      else
          fatalError("unable to load image path " + filePath);
  
      _texture = newTexture;
      return _texture != nullptr;
  }
  
  void TextureManager::draw(int x, int y, SDL_Rect* clip, SDL_Renderer* renderer)
  {
      SDL_Rect renderQuad = { x, y, _width, _height };
  
      if (clip != nullptr)
      {
          renderQuad.w = clip-&gt;w;
          renderQuad.h = clip-&gt;h;
      }
  
      SDL_RenderCopy(renderer, _texture, clip, &amp;renderQuad);
  }
  
  void TextureManager::free()
  {
      if (_texture != nullptr)
      {
          SDL_DestroyTexture(_texture);
          _texture = nullptr;
          _width = 0;
          _height = 0;
      }
  }
  </code></pre>
  
  <p>Player.h</p>
  
  <pre><code>#pragma once
  
  #include "TextureManager.h"
  
  class Player
  {
  public:
      Player(void);
      ~Player(void);
  
      void draw(int x, int y, SDL_Rect* clip, SDL_Renderer* renderer);
  
  private:
      TextureManager _textureManager;
  };
  </code></pre>
  
  <p>Player.cpp</p>
  
  <pre><code>#include "Player.h"
  
  
  Player::Player(void)
  {
  }
  
  
  Player::~Player(void)
  {
  }
  
  void Player::draw(int x, int y, SDL_Rect* clip, SDL_Renderer* renderer)
  {
      _textureManager.draw(x, y, clip, renderer);
  }
  </code></pre>