Particle Render function

The final function in our Particle class is the Render function. The Emitter class calls this function for every active particle in the particle pool. The function sets the alpha and color channel values on the sprite texture used by the particle. It then checks the m_align_rotation flag to see if the texture needs to be copied to the back buffer using SDL_RenderCopy or SDL_RederCopyEx. The difference between these two render calls is that SDL_RenderCopyEx allows the copy to be rotated or flipped. Both of these functions use the m_src rectangle to determine a rectangle inside of the texture to copy.  Both use the m_dest rectangle to determine the destination in the back buffer, where we copy our texture data:

void Particle::Render() {

SDL_SetTextureAlphaMod(m_sprite_texture,
(Uint8)m_alpha );

if( m_color_mod == true ) {
SDL_SetTextureColorMod(m_sprite_texture,
m_current_red,
m_current_green,
m_current_blue );
}

if( m_align_rotation == true ) {
SDL_RenderCopyEx( renderer, m_sprite_texture, &m_src, &m_dest,
m_rotation, NULL, SDL_FLIP_NONE );
}
else {
SDL_RenderCopy( renderer, m_sprite_texture, &m_src, &m_dest );
}
}

In the next section, we will discuss how to modify our Emitter class to accommodate our improvements.