title: Changing text color when mouseover SDL2
body: <p>I'm trying to change the color of the text when hovering over. I can't see why it's not working.</p>
  
  <p>I have tried many diffrent things but can't seem to find a solution to my problem.</p>
  
  <p>Mabey I need to use something else then <code>SDL_FreeSurface</code>?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>int MainGame::mainMenu(){
      TTF_Font *font;
      TTF_Init();
      font = TTF_OpenFont("Myfont.TTF", 30);
  
      int x, y;
      const int NUMMENU = 2;
      const char* labels[NUMMENU] = { "Play", "Exit" };
      SDL_Surface* menus[NUMMENU];
      bool selected[NUMMENU] = { 0, 0 };
      SDL_Color color[2] = { { 255, 255, 255 }, { 255, 0, 0 } };
  
      SDL_Window* window = NULL;
  
      window = SDL_CreateWindow(
          "Main menu",
          SDL_WINDOWPOS_CENTERED,
          SDL_WINDOWPOS_CENTERED,
          1024,
          768,
          SDL_WINDOW_SHOWN
      );
      SDL_Renderer* renderer = SDL_CreateRenderer(window, -1,       SDL_RENDERER_ACCELERATED);
  
  
      menus[0] = TTF_RenderText_Solid(font, labels[0], color[0]);
      menus[1] = TTF_RenderText_Solid(font, labels[1], color[0]);
  
      SDL_Texture* Play = SDL_CreateTextureFromSurface(renderer, menus[0]);
      SDL_Texture* Exit = SDL_CreateTextureFromSurface(renderer, menus[1]);
  
  
      SDL_Rect pos[NUMMENU];
      pos[0].x = 330;
      pos[0].y = 250;
      pos[0].w = 200;
      pos[0].h = 100;
      pos[1].x = 330;
      pos[1].y = 380;
      pos[1].w = 200;
      pos[1].h = 100;
  
      SDL_Event event;
  
  
      while (1)
      {
          SDL_RenderClear(renderer);
          SDL_RenderCopy(renderer, Play, NULL, &amp;pos[0]);
          SDL_RenderCopy(renderer, Exit, NULL, &amp;pos[1]);
          SDL_RenderPresent(renderer);
          t = SDL_GetTicks();
  
          while (SDL_PollEvent(&amp;event))
          {
              switch (event.type)
              {
                  case SDL_QUIT:
                      SDL_FreeSurface(menus[0]);
                      SDL_FreeSurface(menus[1]);
                      return 1;
                  case SDL_MOUSEMOTION:
                      x = event.motion.x;
                      y = event.motion.y;
  
                      for (int i = 0; i &lt; NUMMENU; i += 1) {
                          if (x &gt;= pos[i].x &amp;&amp; x &lt;= pos[i].x + pos[i].w &amp;&amp; y &gt;= pos[i].y &amp;&amp; y &lt;= pos[i].y + pos[i].h)
                          {
                              if (!selected[i]) // this part
                              {
                                  selected[i] = 1;
                                  SDL_FreeSurface(menus[i]);
                                  menus[i] = TTF_RenderText_Solid(font, labels[i], color[1]);
                              }
                          }
                          else
                          {
                              if (selected[i])
                              {
                                  selected[i] = 0;
                                  SDL_FreeSurface(menus[i]);
                                  menus[i] = TTF_RenderText_Solid(font, labels[i], color[0]);
                              }
                          }
                      }
                      break;
                  case SDL_MOUSEBUTTONDOWN:
                      x = event.button.x;
                      y = event.button.y;
                      for (int i = 0; i &lt; NUMMENU; i += 1) {
                          if (x &gt;= pos[i].x &amp;&amp; x &lt;= pos[i].x + pos[i].w &amp;&amp; y &gt;= pos[i].y &amp;&amp; y &lt;= pos[i].y + pos[i].h)
                          {
                              SDL_FreeSurface(menus[0]);
                              SDL_FreeSurface(menus[1]);
                              return i;
                          }
                      }
                      break;
                  case SDL_KEYDOWN:
                      if (event.key.keysym.sym == SDLK_ESCAPE)
                      {
                          SDL_FreeSurface(menus[0]);
                          SDL_FreeSurface(menus[1]);
                          return 0;
                      }
              }
          }
      }
  
      SDL_DestroyRenderer(renderer);
      SDL_DestroyWindow(window);
      SDL_Quit();
  }
  </code></pre>