title: SDL bmp image background
body: <p>As you can see below there is bmp image but its background color is white:</p>
  
  <p><a href="https://i.stack.imgur.com/33wdf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/33wdf.png" alt="enter image description here"></a>
  <br></p>
  
  <p>How can i change it to be for example black (without editing the bmp image itself)?</p>
  
  <p>Here I have code to show bmp image on window:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include "SDL.h"
  
  using namespace std;
  
  int main(int argc, char *args[])
  {
      SDL_Window *window = nullptr;
      SDL_Renderer *renderer = nullptr;
      SDL_Surface *surface = nullptr;
      SDL_Texture *texture = nullptr;
      SDL_Event event;
  
      SDL_Rect positionRect;
      SDL_Rect dimensionRect;
  
      positionRect.x = 0;
      positionRect.y = 0;
      positionRect.w = 100;
      positionRect.h = 100;
  
      dimensionRect.x = 0;
      dimensionRect.y = 0;
      dimensionRect.w = 300;
      dimensionRect.h = 300;
  
  
      if (SDL_Init(SDL_INIT_EVERYTHING) &lt; 0) {
          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't initialize SDL: %s", SDL_GetError());
          return 1;
      }
  
      if (SDL_CreateWindowAndRenderer(500, 500, SDL_WINDOW_OPENGL, &amp;window, &amp;renderer)) {
          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window and renderer: %s", SDL_GetError());
          return 1;
      }
  
      surface = SDL_LoadBMP("sample.bmp");
      if (!surface) {
          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create surface from image: %s", SDL_GetError());
          return 1;
      }
  
      texture = SDL_CreateTextureFromSurface(renderer, surface);
      if (!texture) {
          SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create texture from surface: %s", SDL_GetError());
          return 1;
      }
  
      SDL_FreeSurface(surface);
      surface = nullptr;
  
      while (1) {
          SDL_PollEvent(&amp;event);
          if (event.type == SDL_QUIT) {
              break;
          }
          //SDL_SetRenderDrawColor(renderer, 0xff000000, 0x00ff0000, 0x0000ff00, 0x000000ff);
          SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0x00, 0x00);
          SDL_RenderClear(renderer);
          SDL_RenderCopy(renderer, texture, &amp;positionRect, &amp;dimensionRect);
          SDL_RenderPresent(renderer);
      }
  
      SDL_DestroyTexture(texture);
      SDL_DestroyRenderer(renderer);
      SDL_DestroyWindow(window);
  
      SDL_Quit();
  
      return 0;
  }
  </code></pre>