title: SDL2: Generate fully transparent texture
body: <p>How using SDL_CreateTexture create transparent texture? By default I'm creating texure with such code:</p>
  
  <pre><code>SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_TARGET, x, y);
  </code></pre>
  
  <p>And then I'm paining on this texture with redirecting output to this texture. However at the end what I want to render this on screen any (nonupdated) pixel is black.</p>
  
  <p>I have tried different ways with using of:</p>
  
  <pre><code> SDL_RenderClear(_Renderer);
  </code></pre>
  
  <p>or even with drawing and on created texture with painting transparent Rect with different blending modes but all I had as a result was still nontransparent texture :/</p>
  
  <pre><code>   SDL_Rect rect={0,0,Width,Height};
     SDL_SetRenderDrawBlendMode(_Renderer,SDL_BLENDMODE_BLEND);
     SDL_SetRenderDrawColor(_Renderer,255,255,255,0);
     SDL_RenderFillRect(_Renderer,&amp;rect);
  </code></pre>
  
  <p>To be more specific:</p>
  
  <pre><code>    //this-&gt;texDefault.get()-&gt;get() = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888,SDL_TEXTUREACCESS_TARGET, x, y);
      SDL_SetRenderTarget(_Renderer.get()-&gt;get(), this-&gt;texDefault.get()-&gt;get());
      SDL_SetRenderDrawBlendMode(this-&gt;_Renderer.get()-&gt;get(),SDL_BLENDMODE_NONE);
      SDL_SetRenderDrawColor(this-&gt;_Renderer.get()-&gt;get(),255,0,255,0);
      SDL_RenderClear(this-&gt;_Renderer.get()-&gt;get());
      //SDL_Rect rect={0,0,Width,Height};
      //SDL_SetRenderDrawColor(this-&gt;_Renderer.get()-&gt;get(),255,255,255,255);
      //SDL_RenderFillRect(this-&gt;_Renderer.get()-&gt;get(),&amp;rect);
      //SDL_RenderClear(this-&gt;_Renderer.get()-&gt;get());
      //SDL_SetRenderDrawBlendMode(this-&gt;_Renderer.get()-&gt;get(),SDL_BLENDMODE_NONE);
      SDL_SetRenderTarget(_Renderer.get()-&gt;get(), NULL);
      SDL_Rect rect= {relTop+Top,relLeft+Left,Height,Width};
      SDL_SetRenderDrawBlendMode(this-&gt;_Renderer.get()-&gt;get(),SDL_BLENDMODE_BLEND);
      SDL_RenderCopy(this-&gt;_Renderer.get()-&gt;get(), this-&gt;texDefault-&gt;get(), NULL, &amp;rect);
  </code></pre>
  
  <p>This code is always producing nontransparent Texture independenty what i will set for blending and alpha</p>
  
  <p>The result is :</p>
  
  <p><a href="https://i.stack.imgur.com/kyo0C.jpg" rel="noreferrer"><img src="https://i.stack.imgur.com/kyo0C.jpg" alt="enter image description here"></a></p>
  
  <p>Maybe there is some other simple method to create transparent empty texture in SDL2 something like x/y-sized fully transparent png but loading having such image in file is little bit pointless :/</p>