Add texture alpha blending

This commit is contained in:
zv0n 2021-03-07 13:18:58 +01:00
parent fbc1fdd6f7
commit c7ec12584c
4 changed files with 19 additions and 1 deletions

View File

@ -12,7 +12,7 @@ void RenderObject::render() {
polygon->render( *renderer );
if ( texture != NULL ) {
SDL_Rect *src = NULL;
if(!entireTexture())
if ( !entireTexture() )
src = &src_rect;
SDL_RenderCopy( renderer->getRendererPtr(),
texture->getTexturePtr(), src, &rect );
@ -186,4 +186,13 @@ void RenderObject::copyTo( std::shared_ptr< RenderObject > other ) {
}
other->colidedWith.clear();
}
void RenderObject::setTextureAlpha( uint8_t alpha ) {
texture->setAlpha( alpha );
}
void RenderObject::setTextureSourceRect( SDL_Rect source_rect ) {
src_rect = source_rect;
}
void RenderObject::setTextureSourceRect( int x, int y, int w, int h ) {
setTextureSourceRect( { x, y, w, h } );
}
} // namespace SDLPP

View File

@ -86,6 +86,9 @@ public:
bool isStatic();
void setStatic( bool stat = true );
std::shared_ptr< Renderer > getRenderer() const;
void setTextureAlpha( uint8_t alpha );
void setTextureSourceRect( SDL_Rect source_rect );
void setTextureSourceRect( int x, int y, int w, int h );
protected:
virtual void copyTo( std::shared_ptr< RenderObject > other );

View File

@ -73,4 +73,9 @@ void Texture::setTextureFromSurface( std::shared_ptr< Renderer > &renderer,
}
SDL_FreeSurface( surface );
}
void Texture::setAlpha( uint8_t alpha ) {
SDL_SetTextureBlendMode( texture, SDL_BLENDMODE_BLEND );
SDL_SetTextureAlphaMod( texture, alpha );
}
} // namespace SDLPP

View File

@ -22,6 +22,7 @@ public:
const int outline_size = -1 );
virtual ~Texture();
SDL_Texture *getTexturePtr();
void setAlpha( uint8_t alpha );
private:
void setTextureFromSurface( std::shared_ptr< Renderer > &renderer,