29 #include "nomlib/graphics/Renderer.hpp"
34 { SDL_RENDERER::UniquePtr (
nullptr, priv::FreeRenderTarget ) }
36 NOM_LOG_TRACE ( NOM );
42 NOM_LOG_TRACE ( NOM );
49 NOM_LOG_TRACE ( NOM );
51 this->
renderer_.reset ( SDL_CreateRenderer ( window, rendering_driver, context_flags ) );
79 SDL_RenderGetScale ( this->
renderer(), &scale_factor.x, &scale_factor.y );
88 SDL_RenderGetLogicalSize ( this->
renderer(), &size.x, &size.y );
98 SDL_RenderGetViewport ( this->
renderer(), &v );
102 view_pos.width = v.w;
103 view_pos.height = v.h;
112 if ( SDL_GetRenderDrawBlendMode ( this->
renderer(), &blend ) != 0 )
114 NOM_LOG_ERR ( NOM, SDL_GetError() );
125 if ( SDL_GetRendererOutputSize ( this->
renderer(), &size.x, &size.y ) != 0 )
127 NOM_LOG_ERR ( NOM, SDL_GetError() );
137 SDL_Rect clip_bounds;
139 SDL_RenderGetClipRect( this->
renderer(), &clip_bounds );
141 return Coords( clip_bounds.x, clip_bounds.y, clip_bounds.w, clip_bounds.h );
146 SDL_RenderPresent ( this->
renderer() );
151 if ( SDL_SetRenderTarget ( this->
renderer(), input_texture ) != 0 )
153 NOM_LOG_ERR ( NOM, SDL_GetError() );
161 if ( SDL_RenderClear ( this->
renderer() ) != 0 )
163 NOM_LOG_ERR ( NOM, SDL_GetError() );
172 if ( this->set_color ( color ) ==
false )
177 if ( this->
clear() ==
false )
187 if ( SDL_RenderSetLogicalSize ( this->
renderer(), width, height ) != 0 )
189 NOM_LOG_ERR ( NOM, SDL_GetError() );
199 SDL_Rect area = SDL_RECT(rect);
201 if ( SDL_RenderSetViewport ( this->
renderer(), &area ) != 0 )
203 NOM_LOG_ERR ( NOM, SDL_GetError() );
209 if ( SDL_RenderSetViewport ( this->
renderer(),
nullptr ) != 0 )
211 NOM_LOG_ERR ( NOM, SDL_GetError() );
219 bool Renderer::set_color (
const Color& color )
221 if ( SDL_SetRenderDrawColor ( this->
renderer(), color.red, color.green, color.blue, color.alpha ) != 0 )
223 NOM_LOG_ERR ( NOM, SDL_GetError() );
231 if ( SDL_SetRenderDrawBlendMode ( this->
renderer(), mode ) != 0 )
233 NOM_LOG_ERR ( NOM, SDL_GetError() );
243 if ( SDL_RenderSetClipRect( this->
renderer(),
nullptr ) != 0 )
245 NOM_LOG_ERR ( NOM, SDL_GetError() );
252 SDL_Rect
bounds = SDL_RECT ( clip_bounds );
253 if ( SDL_RenderSetClipRect( this->
renderer(), &bounds ) != 0 )
255 NOM_LOG_ERR ( NOM, SDL_GetError() );
264 void*
pixels =
static_cast<uint32*
> ( malloc (this->
size().x * this->
size().y * 4) );
266 if ( SDL_RenderReadPixels( this->
renderer(),
272 this->
size().x * 4 ) != 0 )
274 NOM_LOG_ERR( NOM, SDL_GetError() );
const Point2i size(void) const
const Coords bounds(void) const
SDL_RENDERER::UniquePtr renderer_
Renderer(void)
Default constructor; initializes instance to sane defaults.
static const Coords null
Convenience object that will always contain a value of -1.
const Point2i scale_factor(void) const
Obtain the current scale factor.
const SDL_BlendMode blend_mode(void) const
Obtain the blending mode used for drawing.
bool set_blend_mode(const SDL_BlendMode mode)
virtual ~Renderer(void)
Lazy destructor with nothing to do.
bool renderer_valid(void) const
Is this object initialized? Valid when NOT nullptr.
bool fill(const Color &color=Color::Blue)
bool set_bounds(const Coords &clip_bounds)
bool set_viewport(const Coords &rect)
const Point2i logical_resolution(void) const
void update(void) const
Update the renderer surface on the attached window.
SDL_RENDERER::RawPtr renderer(void) const
Get a raw pointer to the SDL_Renderer in use.
bool initialize(SDL_WINDOW::RawPtr window, int32 rendering_driver=-1, uint32 context_flags=SDL_RENDERER_ACCELERATED)
Coordinate values (x, y, z, width, height ) wrapper.
bool set_logical_resolution(int width, int height)
Utility class container for RGBA colors.
void * pixels(void) const
const Coords viewport(void) const