title: SDL_SetRenderTarget (SDL2)
body: <p>I have two examples which should work equally in my opinion.
  <strong>But it works in one case and it does not in second case.</strong>
  I need to use second case in my code. I need to refer a texture adress 
  to another function for allocate texture and make some changes on the texture and copy it to renderer.
  But it does not work. Can anybody help with this. I am a beginner so I think it must be some elementary mistake. Thanks everybody who read this.</p>
  
  <p><strong>Here there is my simplified code in two cases:</strong></p>
  
  <p><strong>First case works:</strong></p>
  
  <pre><code>/*---------------------------------in main.c----------------------------*/
  
  #include "global.h"
  
  int main(/*...*/)
  {
      create_txt_texture();
      to_screen(); /*Here there is red color on a screen*/
  
      return 0;
  }
  
      /*-------------------------------in program.c-------------------------*/
  
  #include "global.h"
  
  int create_txt_texture()
  {
      texture = SDL_CreateTexture(renderer, /*...*/);
  
      txt_to_bitmap();
  
      return 0;
  }
  
  void txt_to_bitmap()
  {
      SDL_SetRenderTarget(renderer, texture);
  
      SDL_SetRenderDrawColor(renderer,255,0,0,255); 
      SDL_RenderClear(renderer);  /*filling target with red color*/
  
      SDL_SetRenderTarget(renderer, NULL);
  }
  
  void to_screen()
  {
      SDL_RenderCopy(renderer, texture, NULL, NULL);
      SDL_RenderPresent(renderer); /*Here there is red color on a screen*/
  }
  
      /*-------------------------------in global.h-------------------------*/
  
  #ifndef __GLOBAL_H__
  #define __GLOBAL_H__
  
  SDL_Renderer *renderer;
  SDL_Texture *texture;
  
  void to_screen();
  void txt_to_bitmap();
  int create_txt_texture();
  
  #endif
  </code></pre>
  
  <p><strong>Second case does not work:</strong></p>
  
  <pre><code>/*-------------------------------in main.c-------------------------------*/
  
  #include "global.h"
  
  int main(/*...*/)
  {
      create_txt_texture(texture);
      to_screen(); /*Here there is not red color on a screen*/
  
      return 0;
  }
  
      /*-------------------------------in program.c-------------------------*/
  
  #include "global.h"
  
  int create_txt_texture(SDL_Texture *final_texture)
  {
      final_texture = SDL_CreateTexture(renderer, /*...*/);
  
      txt_to_bitmap(final_texture);
  
      return 0;
  }
  
  void txt_to_bitmap(SDL_Texture *final_texture)
  {
      SDL_SetRenderTarget(renderer, final_texture);
  
      SDL_SetRenderDrawColor(renderer,255,0,0,255); 
      SDL_RenderClear(renderer);  /*filling target with red color*/
  
      SDL_SetRenderTarget(renderer, NULL);
  }
  
  void to_screen()
  {
      SDL_RenderCopy(renderer, texture, NULL, NULL);
      SDL_RenderPresent(renderer); /*Here there is not red color on a screen*/
  }
  
      /*-------------------------------in global.h---------------------------*/
  
  #ifndef __GLOBAL_H__
  #define __GLOBAL_H__
  
  SDL_Renderer *renderer;
  SDL_Texture *texture;
  
  void to_screen();
  void txt_to_bitmap(SDL_Texture *final_texture);
  int create_txt_texture(SDL_Texture *final_texture);
  
  #endif
  </code></pre>