Rose
Classes | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | Friends | List of all members
rose::sdl::Renderer Class Reference

Written as a workaround for an issue in the SDL2 Library. More...

#include <Renderer.h>

Classes

class  RendererDestroy
 A functor to destroy an SDL_Renderer. More...
 

Public Member Functions

 Renderer ()=default
 Construct an empty renderer.
 
 Renderer (const Renderer &renderer)=delete
 Deleted copy constructor.
 
 Renderer (Window &window, int index, Uint32 flags)
 Construct a renderer associated with a Window. More...
 
 Renderer (Renderer &&renderer) noexcept=default
 Move constructor defaulted. More...
 
Rendereroperator= (const Renderer &renderer)=delete
 Deleted copy assignment operator.
 
Rendereroperator= (Renderer &&renderer)=default
 Move assignment operator. More...
 
 operator bool () const noexcept
 Test the renderer. More...
 
auto get () const
 The the underlying SDL_Renderer* for use with the SDL2 API. More...
 
void setDrawBlendMode (SDL_BlendMode blendMode)
 Set the SDL_BlendMode on the renderer. More...
 
Texture createTexture (Size size)
 Create a Texture with the given size. More...
 
void copyFullTexture (sdl::Texture &source, sdl::Texture &destination)
 Copy source Texture to destination Texture and set the BlendMode on the destination Texture. More...
 
int renderClear ()
 Calls SDL_RenderClear on the renderer. More...
 
void renderPresent ()
 Calls SDL_RenderPresent on the renderer.
 
int renderCopy (const Texture &texture)
 Calls SDL_RenderCopy to copy the source texture to the current render target. More...
 
int renderCopy (const Texture &texture, Rectangle dst)
 Calls SDL_RenderCopy to copy the source texture to the current target at a destination Rectangle. More...
 
int renderCopy (const Texture &texture, Rectangle src, Rectangle dst)
 Calls SDL_RenderCopy to copy the source texture from a source Rectangle to the current target at a destination Rectangle. More...
 
int renderCopy (GradientTexture &texture, Rectangle dst)
 Render copy a GradientTexture kernel across the destination Rectangle. More...
 
int renderCopyEx (Texture &texture, Rectangle src, Rectangle dst, double angle, RenderFlip renderFlip, std::optional< Position > point=std::nullopt) const
 Render with extras. More...
 
int fillRect (Rectangle rectangle, color::RGBA color)
 Calls SDL_RenderFillRect after setting the RenderDrawColor to color. More...
 
int drawLine (int x0, int y0, int x1, int y1)
 Render a line. More...
 
int drawPoint (const Position &position, const color::RGBA &rgba)
 
template<class C >
int drawLines (C pointsContainer)
 Render lines. More...
 

Protected Types

using RendererPtr = std::unique_ptr< SDL_Renderer, RendererDestroy >
 An SDL_Renderer unique pointer.
 

Protected Member Functions

int popRenderTarget ()
 Pop a render target off the stack. More...
 
int pushRenderTarget (sdl::Texture &texture)
 Set a new render target, and push it onto the stack. More...
 
int pushRenderTarget ()
 Set the render target to the default, and push it onto the stack. More...
 

Protected Attributes

RendererPtr mRenderer {}
 The Renderer.
 
std::stack< SDL_Texture * > mTargetTextureStack {}
 The stack of render targets.
 

Friends

class RenderTargetGuard
 

Detailed Description

Written as a workaround for an issue in the SDL2 Library.

https://stackoverflow.com/questions/50415099/sdl-setrendertarget-doesnt-set-the-tartget

Constructor & Destructor Documentation

◆ Renderer() [1/2]

rose::sdl::Renderer::Renderer ( Window window,
int  index,
Uint32  flags 
)

Construct a renderer associated with a Window.

Parameters
windowThe associated Window.
indexThe index argument to SDL_CreateRenderer.
flagsThe flags argument to SDL_CreateRenderer.

◆ Renderer() [2/2]

rose::sdl::Renderer::Renderer ( Renderer &&  renderer)
defaultnoexcept

Move constructor defaulted.

Parameters
rendererThe Renderer to move.

Member Function Documentation

◆ copyFullTexture()

void rose::sdl::Renderer::copyFullTexture ( sdl::Texture source,
sdl::Texture destination 
)

Copy source Texture to destination Texture and set the BlendMode on the destination Texture.

The function uses RenderTargetGuard to temporarily set the render Target to the destination, calls SDL_RenderCopy to copy the texture, and sets the BlendMode on the destination texture to SDL_BLENDMODE_BLEND.

Parameters
source
destination

◆ createTexture()

Texture rose::sdl::Renderer::createTexture ( Size  size)

Create a Texture with the given size.

Parameters
sizeThe Texture size.
Returns
a new Texture object.

◆ drawLine()

int rose::sdl::Renderer::drawLine ( int  x0,
int  y0,
int  x1,
int  y1 
)

Render a line.

Parameters
x0Start point X
y0Start point Y
x1End point X
y1End point Y
Returns
The SDL2 API return status code.

◆ drawLines()

template<class C >
int rose::sdl::Renderer::drawLines ( pointsContainer)
inline

Render lines.

The container contains a list of Position objects.

Template Parameters
CThe container type.
Parameters
pointsContainerThe points container.
Returns
The SDL2 API return status code.

◆ fillRect()

int rose::sdl::Renderer::fillRect ( Rectangle  rectangle,
color::RGBA  color 
)

Calls SDL_RenderFillRect after setting the RenderDrawColor to color.

The existing RenderDrawColor is saved and restored.

Parameters
rectangleThe rectangle to fill.
colorThe fill color.
Returns
The return status of SDL_RenderFillRect.

◆ get()

auto rose::sdl::Renderer::get ( ) const
inline

The the underlying SDL_Renderer* for use with the SDL2 API.

Returns
An SDL_Renderer*

◆ operator bool()

rose::sdl::Renderer::operator bool ( ) const
inlineexplicitnoexcept

Test the renderer.

Returns
false if the renderer is empty, true if it is valid.

◆ operator=()

Renderer& rose::sdl::Renderer::operator= ( Renderer &&  renderer)
default

Move assignment operator.

Parameters
rendererThe renderer to assign, this becomes empty after the assignment.
Returns
A reference to this renderer.

◆ popRenderTarget()

int rose::sdl::Renderer::popRenderTarget ( )
inlineprotected

Pop a render target off the stack.

If there are none, set the default render target.

The top of the stack is the current render target, unless the default is current in which case the stack will be empty. If the stack has 1 or 0 render targets on it, the renderer is set to the default target.

Returns
The return status of SDL_SetRenderTarget

◆ pushRenderTarget() [1/2]

int rose::sdl::Renderer::pushRenderTarget ( sdl::Texture texture)
protected

Set a new render target, and push it onto the stack.

Parameters
textureThe new render target.
Returns
The return status of SDL_SetRenderTarget

◆ pushRenderTarget() [2/2]

int rose::sdl::Renderer::pushRenderTarget ( )
inlineprotected

Set the render target to the default, and push it onto the stack.

Returns
The return status of SDL_SetRenderTarget

◆ renderClear()

int rose::sdl::Renderer::renderClear ( )
inline

Calls SDL_RenderClear on the renderer.

Returns
The return status from SDL_RenderClear.

◆ renderCopy() [1/4]

int rose::sdl::Renderer::renderCopy ( const Texture texture)

Calls SDL_RenderCopy to copy the source texture to the current render target.

SDL_RenderCopy is called with nullptr for srcrect and dstrect.

Parameters
textureThe texture to copy.
Returns
The return status of SDL_RenderCopy.

◆ renderCopy() [2/4]

int rose::sdl::Renderer::renderCopy ( const Texture texture,
Rectangle  dst 
)

Calls SDL_RenderCopy to copy the source texture to the current target at a destination Rectangle.

Parameters
textureThe sdl::Texture
dstThe destination RectangleInt
Returns
The return status of SDL_RenderCopy.

◆ renderCopy() [3/4]

int rose::sdl::Renderer::renderCopy ( const Texture texture,
Rectangle  src,
Rectangle  dst 
)

Calls SDL_RenderCopy to copy the source texture from a source Rectangle to the current target at a destination Rectangle.

Parameters
textureThe Texture.
srcThe source Rectangle.
dstThe destination Rectangle.
Returns
The return status of SDL_RenderCopy.

◆ renderCopy() [4/4]

int rose::sdl::Renderer::renderCopy ( GradientTexture texture,
Rectangle  dst 
)

Render copy a GradientTexture kernel across the destination Rectangle.

Parameters
textureThe GradientTexture.
dstThe destination Rectangle.
Returns
The return status of SDL_RenderCopy.

◆ renderCopyEx()

int rose::sdl::Renderer::renderCopyEx ( Texture texture,
Rectangle  src,
Rectangle  dst,
double  angle,
RenderFlip  renderFlip,
std::optional< Position point = std::nullopt 
) const

Render with extras.

Parameters
srcSource Rectangle
dstDestination Rectangle
angleRotation Angle
renderFlipFlip
pointRotation Position if specified.
Returns
Stastus code returned by SDL_RenderCopyEx()

◆ setDrawBlendMode()

void rose::sdl::Renderer::setDrawBlendMode ( SDL_BlendMode  blendMode)
inline

Set the SDL_BlendMode on the renderer.

Parameters
blendMode

The documentation for this class was generated from the following files: