When drawing clear PNG information on to the renderer, pixel information of any earlier drawing (layer beneath) is changed with the renderer’s drawing coloration (inexperienced).
I’ve tried setting mix mode within the renderer, floor (used to load pixel information), 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 picture information
SDL_Texture* TextureLoader::load(string adpath) {
SDL_Surface* floor = IMG_Load(adpath.c_str());
if (floor == nullptr) {
return nullptr;
}
SDL_SetSurfaceBlendMode(floor, SDL_BLENDMODE_BLEND);
SDL_Texture* texture = SDL_CreateTextureFromSurface(GetViewport()->getRenderer(), floor);
SDL_FreeSurface(floor);
if (texture == nullptr) {
return nullptr;
}
SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
return texture;
}
// attracts 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);
}
// technique referred to as throughout sport loop to attract out there textures (pseudo code for simplicity)
void Viewport::draw() {
SDL_RenderClear(this->renderer);
// draw background beneath
this->drawTexture(this->background, this->b_rect, this->r_rect);
// draw fps above (PNG bitmap font with clear pixels round every glyph)
this->drawTexture(this->fps, this->f_rect, this->f_rect);
SDL_RenderPresent(this->renderer);
}
When trying to find an answer, the solutions are to make use of SDL_SetRenderDrawBlendMode
, SDL_SetSurfaceBlendMode
, & SDL_SetTextureBlendMode
& set them to SDL_BLENDMODE_BLEND
. However none are working.
I’ve additionally tried the IMG_LoadTexture
to load PNGs with the identical outcome.
Word: All my testing up to now has been on Home windows. I have never but had the chance to see the outcome on different programs. So I would not be stunned if it is a platform-specific concern.