-
Notifications
You must be signed in to change notification settings - Fork 0
/
SDLLibrary.cpp
76 lines (62 loc) · 1.82 KB
/
SDLLibrary.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include "SDLLibrary.h"
#include <stdexcept>
#include <string>
sdl::Library::Library( Uint32 flags )
{
if ( SDL_Init( flags ) != 0 )
{
throw std::runtime_error( std::string( "Could not initialize SDL video system: " ) + SDL_GetError( ) );
}
}
sdl::Library::~Library()
{
SDL_Quit( );
}
sdl::Renderer::Renderer( SDL_Renderer* sdl_renderer_ptr )
: m_sdl_renderer_ptr( sdl_renderer_ptr )
{}
sdl::Renderer::~Renderer( )
{
SDL_DestroyRenderer( m_sdl_renderer_ptr );
}
void sdl::Renderer::clear( )
{
SDL_RenderClear( m_sdl_renderer_ptr );
}
void sdl::Renderer::present( )
{
SDL_RenderPresent( m_sdl_renderer_ptr );
}
void sdl::Renderer::set_draw_color( Uint8 r, Uint8 g, Uint8 b, Uint8 a )
{
SDL_SetRenderDrawColor( m_sdl_renderer_ptr, r, g, b, a );
}
void sdl::Renderer::draw_line( int x1, int y1, int x2, int y2 ) const
{
SDL_RenderDrawLine( m_sdl_renderer_ptr, x1, y1, x2, y2 );
}
void sdl::Renderer::draw_point( int x, int y ) const
{
SDL_RenderDrawPoint( m_sdl_renderer_ptr, x, y );
}
sdl::Window::Window( const char *title, int x, int y, int w, int h, Uint32 flags )
: m_sdl_window_ptr( SDL_CreateWindow( title, x, y, w, h, flags ) )
{
if ( m_sdl_window_ptr == nullptr )
{
throw std::runtime_error( std::string( "Could not create SDL window: " ) + SDL_GetError( ) );
}
}
sdl::Renderer sdl::Window::create_accelerated_renderer( )
{
auto* sdl_renderer_ptr = SDL_CreateRenderer( m_sdl_window_ptr, -1, SDL_RENDERER_ACCELERATED );
if ( sdl_renderer_ptr == nullptr )
{
throw std::runtime_error( std::string( "Could not create SDL renderer: " ) + SDL_GetError( ) );
}
return Renderer( sdl_renderer_ptr );
}
sdl::Window::~Window()
{
SDL_DestroyWindow( m_sdl_window_ptr );
}