Renderer.hpp
1 /******************************************************************************
2 
3  nomlib - C++11 cross-platform game engine
4 
5 Copyright (c) 2013, Jeffrey Carpenter <jeffrey.carp@gmail.com>
6 All rights reserved.
7 
8 Redistribution and use in source and binary forms, with or without
9 modification, are permitted provided that the following conditions are met:
10 
11 1. Redistributions of source code must retain the above copyright notice, this
12  list of conditions and the following disclaimer.
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 
28 ******************************************************************************/
29 #ifndef NOMLIB_SDL2_RENDERER_HPP
30 #define NOMLIB_SDL2_RENDERER_HPP
31 
32 #include <iostream>
33 #include <string>
34 #include <memory>
35 
36 #include "SDL.h"
37 
38 #include "nomlib/config.hpp"
39 #include "nomlib/math/Color.hpp"
40 #include "nomlib/math/Coords.hpp"
41 #include "nomlib/SDL_helpers.hpp"
42 
43 namespace nom {
44 
49 class Renderer
50 {
51  public:
53  Renderer ( void );
54 
56  virtual ~Renderer ( void );
57 
63  bool initialize ( SDL_WINDOW::RawPtr window, int32 rendering_driver = -1, uint32 context_flags = SDL_RENDERER_ACCELERATED );
64 
66  SDL_RENDERER::RawPtr renderer ( void ) const;
67 
69  bool renderer_valid ( void ) const;
70 
74  const Point2i logical_resolution ( void ) const;
75 
79  const Coords viewport ( void ) const;
80 
82  const Point2i scale_factor ( void ) const;
83 
85  const SDL_BlendMode blend_mode ( void ) const;
86 
90  const Point2i size ( void ) const;
91 
95  const Coords bounds ( void ) const;
96 
98  void update ( void ) const;
99 
103  bool update ( SDL_TEXTURE::RawPtr input_texture );
104 
110  bool clear ( void ) const;
111 
117  bool fill ( const Color& color = Color::Blue );
118 
126  bool set_logical_resolution ( int width, int height );
127 
137  bool set_viewport ( const Coords& rect );
138 
139  bool set_color ( const Color& color );
140 
147  bool set_blend_mode ( const SDL_BlendMode mode );
148 
155  bool set_bounds ( const Coords& clip_bounds );
156 
160  void* pixels ( void ) const;
161 
162  protected:
165  SDL_RENDERER::UniquePtr renderer_;
166 };
167 
168 
169 } // namespace nom
170 
171 #endif // include guard defined
const Point2i size(void) const
Definition: Renderer.cpp:121
const Coords bounds(void) const
Definition: Renderer.cpp:135
SDL_RENDERER::UniquePtr renderer_
Definition: Renderer.hpp:165
Renderer(void)
Default constructor; initializes instance to sane defaults.
Definition: Renderer.cpp:33
const Point2i scale_factor(void) const
Obtain the current scale factor.
Definition: Renderer.cpp:75
const SDL_BlendMode blend_mode(void) const
Obtain the blending mode used for drawing.
Definition: Renderer.cpp:108
bool set_blend_mode(const SDL_BlendMode mode)
Definition: Renderer.cpp:229
virtual ~Renderer(void)
Lazy destructor with nothing to do.
Definition: Renderer.cpp:40
bool renderer_valid(void) const
Is this object initialized? Valid when NOT nullptr.
Definition: Renderer.cpp:63
bool fill(const Color &color=Color::Blue)
Definition: Renderer.cpp:170
bool set_bounds(const Coords &clip_bounds)
Definition: Renderer.cpp:239
Video subsystem responsible for managing high-level graphics display (think: very fancy back-buffer)...
Definition: Renderer.hpp:49
bool set_viewport(const Coords &rect)
Definition: Renderer.cpp:195
const Point2i logical_resolution(void) const
Definition: Renderer.cpp:84
void update(void) const
Update the renderer surface on the attached window.
Definition: Renderer.cpp:144
SDL_RENDERER::RawPtr renderer(void) const
Get a raw pointer to the SDL_Renderer in use.
Definition: Renderer.cpp:58
bool clear(void) const
Definition: Renderer.cpp:159
bool initialize(SDL_WINDOW::RawPtr window, int32 rendering_driver=-1, uint32 context_flags=SDL_RENDERER_ACCELERATED)
Definition: Renderer.cpp:47
Coordinate values (x, y, z, width, height ) wrapper.
Definition: Coords.hpp:44
bool set_logical_resolution(int width, int height)
Definition: Renderer.cpp:185
Utility class container for RGBA colors.
Definition: Color.hpp:43
void * pixels(void) const
Definition: Renderer.cpp:262
const Coords viewport(void) const
Definition: Renderer.cpp:93