c++sdlalphasdl-2blending

Alpha Blending in SDL resets after resizing window


I wanted to implement alpha blending within my Texture class. It works almost completely. I use the following functions for manipulating the alpha value:

SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(texture, alpha);

The only problem I have is that the textures that have been manipulated seem to reset to the normal alpha value of 255 when I resize or maximize the window. I checked the alpha value and recognized that it is still the value I manipulated it to be before. So the value is not 255. Why is the renderer rendering it as if the alpha value was 255 then?

Information about how and when I use these functions:

Within the main game loop I change the alpha value of the texture with a public method of my Texture class:

Texture::setAlphaValue(int alpha)

There the private alpha variable of the Texture class is changed.

Within the Draw method of my Texture class the texture is drawn and I call

 SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
 SDL_SetTextureAlphaMod(texture, alpha);

before

 SDL_RenderCopyEx(renderer, texture, &sourceRectangle, &destinationRectangle, 0, 0, SDL_Flip);

Information about how I resize the window:

I basically just set the window mode to a resizable window in my SDL initialization. Then handling it like any normal window is possible:

SDL_CreateWindow(window_Title, x_Position, y_Position, window_Width, window_Height, SDL_WINDOW_RESIZABLE);  

My primary loop area:

This is the main game loop:

 void Game::Render()
 {
     // set color and draw window       

     SDL_SetRenderDrawColor(renderer, windowColor.R(), windowColor.G(), windowColor.B(), 0);

     SDL_RenderClear(renderer); 

     texture.setAlphaValue(100);
     texture.Draw(SDL_FLIP_NONE);

     // present/draw renderer

     SDL_RenderPresent(renderer);   
 }

Test my project:

I also uploaded my alpha-blending test project to dropbox. In this project I simplified everything, there isn't even a texture class anymore. So the code is really simple, but the bug is still there. Here is the link to the Visual Studio project: http://www.dropbox.com/s/zaipm8751n71cq7/Alpha.rar


Solution

  • This has been a reported bug in the SDL library. It is fixed for some time now: https://bugzilla.libsdl.org/show_bug.cgi?id=2202, https://github.com/libsdl-org/SDL/issues/1085