When drawing transparent PNG data on to the renderer, pixel data of any previous drawing (layer beneath) is replaced with the renderer's drawing color (green).
I have tried setting blend mode in the renderer, surface (used to load pixel data), and texture.
Code snippet:
// creates the renderer void Viewport::init(SDL_Window* window) { this->renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED); SDL_SetRenderDrawBlendMode(this->renderer, SDL_BLENDMODE_BLEND); SDL_SetRenderDrawColor(this->renderer, 0, 255, 0, SDL_ALPHA_OPAQUE); } // creates a texture from PNG image data SDL_Texture* TextureLoader::load(string adpath) { SDL_Surface* surface = IMG_Load(adpath.c_str()); if (surface == nullptr) { return nullptr; } SDL_SetSurfaceBlendMode(surface, SDL_BLENDMODE_BLEND); SDL_Texture* texture = SDL_CreateTextureFromSurface(GetViewport()->getRenderer(), surface); SDL_FreeSurface(surface); if (texture == nullptr) { return nullptr; } SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND); return texture; } // draws a texture on renderer void Viewport::drawTexture(SDL_Texture* texture, SDL_Rect s_rect, SDL_Rect t_rect) { if (texture == nullptr) { return; } SDL_RenderCopy(this->renderer, texture, &s_rect, &t_rect); } // method called during game loop to draw available textures (pseudo code for simplicity) void Viewport::draw() { SDL_RenderClear(this->renderer); // draw background underneath this->drawTexture(this->background, this->b_rect, this->r_rect); // draw fps above (PNG bitmap font with transparent pixels around each glyph) this->drawTexture(this->fps, this->f_rect, this->f_rect); SDL_RenderPresent(this->renderer); } When searching for a solution, the suggestions are to use SDL_SetRenderDrawBlendMode, SDL_SetSurfaceBlendMode, & SDL_SetTextureBlendMode & set them to SDL_BLENDMODE_BLEND. But none are working.
I have also tried the IMG_LoadTexture to load PNGs with the same result.
Note: All my testing so far has been on Windows. I haven't yet had the opportunity to see the result on other systems. So I wouldn't be surprised if this is a platform-specific issue.
