GameKit
0.0.1a
C++ gamedev tools
source
core
SDLLoader.cpp
Go to the documentation of this file.
1
/*
2
* =====================================================================================
3
*
4
* Filename: SDLLoader.cpp
5
*
6
* Description:
7
*
8
* Created: 15/09/2014 00:07:14
9
*
10
* Author: Quentin Bazin, <gnidmoo@gmail.com>
11
*
12
* =====================================================================================
13
*/
14
#include "
gk/core/Exception.hpp
"
15
#include "
gk/core/SDLHeaders.hpp
"
16
#include "
gk/core/SDLLoader.hpp
"
17
18
namespace
gk
{
19
20
SDLLoader::~SDLLoader
() {
21
if
(
m_mixInitialized
) Mix_CloseAudio();
22
if
(
m_ttfInitialized
) TTF_Quit();
23
if
(
m_imgInitialized
) IMG_Quit();
24
if
(
m_sdlInitialized
) SDL_Quit();
25
}
26
27
void
SDLLoader::load
() {
28
if
(SDL_Init(SDL_INIT_VIDEO) < 0) {
29
throw
EXCEPTION
(
"SDL init error:"
, SDL_GetError());
30
}
else
{
31
m_sdlInitialized
=
true
;
32
}
33
34
int
imgFlags = IMG_INIT_PNG;
35
if
((!IMG_Init(imgFlags)) & imgFlags) {
36
throw
EXCEPTION
(
"SDL_image init error:"
, IMG_GetError());
37
}
else
{
38
m_imgInitialized
=
true
;
39
}
40
41
if
(TTF_Init() < 0) {
42
throw
EXCEPTION
(
"SDL_ttf init error:"
, TTF_GetError());
43
}
else
{
44
m_ttfInitialized
=
true
;
45
}
46
47
if
(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, MIX_DEFAULT_CHANNELS, 1024) == -1) {
48
throw
EXCEPTION
(
"SDL_mixer init error:"
, Mix_GetError());
49
}
else
{
50
m_mixInitialized
=
true
;
51
}
52
53
Mix_AllocateChannels(32);
54
55
Mix_VolumeMusic(MIX_MAX_VOLUME / 3);
56
Mix_Volume(-1, MIX_MAX_VOLUME);
57
}
58
59
}
// namespace gk
60
SDLHeaders.hpp
gk::SDLLoader::~SDLLoader
~SDLLoader()
Definition:
SDLLoader.cpp:20
gk::SDLLoader::m_imgInitialized
bool m_imgInitialized
Definition:
SDLLoader.hpp:33
gk
Definition:
AudioPlayer.hpp:21
SDLLoader.hpp
gk::SDLLoader::m_sdlInitialized
bool m_sdlInitialized
Definition:
SDLLoader.hpp:32
EXCEPTION
#define EXCEPTION(args...)
Definition:
Exception.hpp:22
gk::SDLLoader::load
void load()
Definition:
SDLLoader.cpp:27
Exception.hpp
gk::SDLLoader::m_ttfInitialized
bool m_ttfInitialized
Definition:
SDLLoader.hpp:34
gk::SDLLoader::m_mixInitialized
bool m_mixInitialized
Definition:
SDLLoader.hpp:35
Generated by
1.8.12