I have an all-black texture which acts as a “veil” for a mini-map which is meant to be “uncovered” (by setting pixels to transparent) as the player moves through the world.
My first attempt involved setting render target to the texture and doing SDL_RenderFillRect()
with SDL_SetRenderDrawColor(renderer,0,0,0,0)
but this did not work.
Now I’m trying something like this:
SDL_Texture * veilTexture = assetStore->GetTexture(MINIMAPVEIL);
SDL_SetRenderDrawBlendMode(renderer, SDL_BLENDMODE_BLEND);
void* pixels;
int pitch;
SDL_LockTexture(veilTexture, NULL, &pixels, &pitch);
Uint32* pixelData = (Uint32*)pixels;
for(int y = 100; y < 120; ++y){
for(int x = 100; x < 120; ++x){
pixelData[y * (pitch / 4) + x] = 0x00000000;
}
}
SDL_UnlockTexture(veilTexture);
This texture was initialized like this:
SDL_Texture * mapveil = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGBA8888, SDL_TEXTUREACCESS_STREAMING, 360, 360)
This approach also isn’t working for me. I believe there is some knowledge that I am lacking in order to proceed with this issue. I am also concerned about the efficiency of this; it updates each pixel individually (I’ve gotten it to update the pixel colors, but I cant seem to update the alpha value) and I wonder if there is a better approach.
Does anyone have a suggestion for how to proceed with something such as this? Thank you.