By tinkering I found a way to do it, but I’m not sure if it’s the best way to do it. Isn’t there a risk of taking too much time if many sprites use this effect ?
Do you have an idea to improve this portion of code:
Thanks.
Do you have an idea to improve this portion of code:
Uint32 format;
int w, h;
SDL_BlendMode blendmodeSrc;
SDL_Texture *pTexture1 = IMG_LoadTexture(renderer, "sp1.png");
SDL_Texture *pTexture2 = IMG_LoadTexture(renderer, "sp2.png");
SDL_QueryTexture(pTexture1, &format, NULL, &w, &h);
SDL_Texture *pTexture3 = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_TARGET, w, h);
SDL_Texture *pTexture4 = SDL_CreateTexture(renderer, format, SDL_TEXTUREACCESS_TARGET, w, h);
SDL_SetTextureBlendMode(pTexture3, SDL_BLENDMODE_NONE);
SDL_SetRenderTarget(renderer, pTexture3);
blendmodeSrc = SDL_ComposeCustomBlendMode(SDL_BLENDFACTOR_SRC_COLOR, SDL_BLENDFACTOR_ZERO, SDL_BLENDOPERATION_ADD, SDL_BLENDFACTOR_DST_ALPHA, SDL_BLENDFACTOR_SRC_ALPHA, SDL_BLENDOPERATION_ADD);
SDL_SetTextureBlendMode(pTexture2, blendmodeSrc);
SDL_RenderCopy(renderer, pTexture1, NULL, NULL);
SDL_RenderCopy(renderer, pTexture2, NULL, NULL);
SDL_SetRenderTarget(renderer, pTexture4);
SDL_SetTextureBlendMode(pTexture3, SDL_BLENDMODE_BLEND);
SDL_SetTextureBlendMode(pTexture4, SDL_BLENDMODE_NONE);
SDL_RenderCopy(renderer, pTexture1, NULL, NULL);
SDL_RenderCopy(renderer, pTexture3, NULL, NULL);
SDL_SetRenderTarget(renderer, NULL);
SDL_SetTextureBlendMode(pTexture4, SDL_BLENDMODE_BLEND);
Result :
Thanks