title: SDL_ttf textures in vector affects other's destination rectangle
body: <p>I was following Lazy Foo' tutorial to create text using ttf font, and everything was fine, but I needed to create several text lines in several different places with different font size and color, so I decided to use vector. Here is my code of TextTexture (mostly copy of Lazy Foo tutorial):</p>
  
  <pre><code>#ifndef TEXT_TEXTURE_HPP
  #define TEXT_TEXTURE_HPP
  
  #include "graphics.hpp"
  #include "vector2.hpp"
  
  #include &lt;SDL2/SDL_ttf.h&gt;
  
  #include &lt;string&gt;
  
  class TextTexture {
  public:
      TextTexture(
          Graphics&amp; graphics,
          TTF_Font* font,
          std::string textureText,
          SDL_Color textColor,
          Vector2 coordinates
      );
  
      ~TextTexture();
  
      void draw( Graphics&amp; graphics );
  
  private:
      SDL_Texture* mTexture;
  
      int mWidth;
      int mHeight;
  
      int mX;
      int mY;
  
  };
  
  #endif // TEXT_TEXTURE_HPP
  </code></pre>
  
  <p>And .cpp file for it:</p>
  
  <pre><code>#include "text_texture.hpp"
  #include "vector2.hpp"
  
  #include &lt;iostream&gt;
  #include &lt;unistd.h&gt;
  
  TextTexture::TextTexture (
      Graphics&amp; graphics,
      TTF_Font* font,
      std::string textureText,
      SDL_Color textColor,
      Vector2 coordinates
  ) :
      mTexture(NULL),
      mWidth(0),
      mHeight(0),
      mX(0),
      mY(0)
  {
      //Render temp surface
       SDL_Surface* tempSurface = TTF_RenderUTF8_Blended (font, textureText.c_str(), textColor);
  
      if ( tempSurface == NULL ) {
          std::cout &lt;&lt; "Unable to render text surface! SDL_ttf Error: " &lt;&lt; TTF_GetError() &lt;&lt; std::endl;
      } else {
          this -&gt; mTexture = SDL_CreateTextureFromSurface(graphics.getRenderer(), tempSurface);
          if ( this -&gt; mTexture == NULL ) {
              std::cout &lt;&lt; "Unable to create texture from rendered text! SDL Error: " &lt;&lt; SDL_GetError() &lt;&lt; std::endl;
          } else {
              //Get image dimensions
              mWidth = tempSurface -&gt; w;
              mHeight = tempSurface -&gt; h;
              // Get coordinates
              this -&gt; mX = coordinates.getX();
              this -&gt; mY = coordinates.getY();
          }
          SDL_FreeSurface (tempSurface);
          tempSurface = NULL;
      }
  }
  
  TextTexture::~TextTexture() {
      //Free texture if it exists
      if ( mTexture != NULL ) {
          SDL_DestroyTexture( mTexture );
      }
      mTexture = NULL;
      mWidth = 0;
      mHeight = 0;
  }
  
  // FIXME somewhy affects previous dest rects
  void TextTexture::draw (Graphics&amp; graphics) {
      //Set rendering space and render to screen
      SDL_Rect destinationRectangle = { mX, mY, this -&gt; mWidth, this -&gt; mHeight };
      //Render to screen
      graphics.blitSurface( mTexture, NULL, &amp;destinationRectangle );
  }
  </code></pre>
  
  <p>I created simple Text Manager to handle vector of texts:</p>
  
  <pre><code>#ifndef TEXT_MANAGER_HPP
  #define TEXT_MANAGER_HPP
  
  #include "graphics.hpp"
  #include "text_texture.hpp"
  #include "vector2.hpp"
  
  #include &lt;string&gt;
  #include &lt;vector&gt;
  
  enum fontSize {
      SMALL = 16,
      NORMAL = 32,
      BIG = 48,
      TITLE = 72
  };
  
  enum fontColor {
      WHITE,
      ORANGE,
      BLACK
  };
  
  class TextManager {
  public:
      TextManager(Graphics&amp; graphics);
      ~TextManager();
  
      void addText(std::string, fontSize, fontColor, Vector2);
      void draw();
      void clearText();
  
  private:
      Graphics&amp; graphics;
      std::vector &lt;TextTexture&gt; gText;
  };
  
  #endif // TEXT_MANAGER_HPP
  </code></pre>
  
  <p>and .cpp file:</p>
  
  <pre><code>#include "text_manager.hpp"
  
  #include &lt;iostream&gt;
  
  TextManager::TextManager(Graphics&amp; graphics) :
      graphics(graphics)
  {}
  
  TextManager::~TextManager() {}
  
  void TextManager::addText(std::string text, fontSize size, fontColor color, Vector2 coordinates) {
  
      TTF_Font* tempFont = TTF_OpenFont( "resources/fonts/pixel.ttf", fontSize::TITLE );
      SDL_Color tempColor = { 255, 255, 255 };
  
      // Switch removed for shorter code
  
      this -&gt; gText.emplace_back(graphics, tempFont, text, tempColor, coordinates);
  
      TTF_CloseFont(tempFont);
      tempFont = NULL;
  }
  // FIXME
  void TextManager::draw() {
      std::vector&lt;TextTexture&gt;::iterator it;
      for(it = gText.begin(); it != gText.end(); ++it) {
          it -&gt; draw(graphics);
      }
  
  }
  
  void TextManager::clearText() {
      gText.clear();
  }
  </code></pre>
  
  <p>But when I start the application, I see something like this:</p>
  
  <p><a href="http://i.stack.imgur.com/rcLVk.png" rel="nofollow">Second string is printed, but font and bonding rectangle of first line is saved, hovewer</a></p>
  
  <p>Later I added input handler that added second line of text after pressing a button, and when there is only one line of text, everything fine, but when you add second, something weird is beginning - sometimes first text disappears, sometimes 'both' of them is shoved. As I understand, second surface of text somehow affects first one, by copying it texture on the place of the first's destination.</p>
  
  <p>Here is my graphics.blitSurface, if it will help:</p>
  
  <pre><code>void Graphics::blitSurface(SDL_Texture* texture, SDL_Rect* sourceRectangle, SDL_Rect* destinationRectangle)
  {
      SDL_RenderCopy ( this -&gt; _renderer, texture, sourceRectangle, destinationRectangle );
  }
  </code></pre>
  
  <p>Where is my mistake? Sorry for bad english, I hope you will get my problem.</p>