-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcSDL2WNDManager.cpp
More file actions
133 lines (112 loc) · 3.58 KB
/
cSDL2WNDManager.cpp
File metadata and controls
133 lines (112 loc) · 3.58 KB
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
==================================================================================
cSDL2WNDManager.cpp
==================================================================================
*/
#include "cSDL2WNDManager.h"
cSDL2WNDManager* cSDL2WNDManager::pInstance = NULL;
/*
=================================================================================
Constructor
=================================================================================
*/
cSDL2WNDManager::cSDL2WNDManager()
{
}
/*
=================================================================================
Singleton Design Pattern
=================================================================================
*/
cSDL2WNDManager* cSDL2WNDManager::getInstance()
{
if (pInstance == NULL)
{
pInstance = new cSDL2WNDManager();
}
return cSDL2WNDManager::pInstance;
}
/*
=================================================================================
* Initialise the SDL Context with desired Window Title String, width and height
* @param strWNDTitle The Window Title String
* @param iWidth The width of the window to draw
* @param iHeight The height of the window to draw
=================================================================================
*/
bool cSDL2WNDManager::initWND(string strWNDTitle, int iWidth, int iHeight)
{
bool wndCreated = createSDLWnd(strWNDTitle, iWidth, iHeight, SDL_WINDOW_OPENGL);
return wndCreated;
}
/*
=======================================================================================================
* Initialise the SDL Context with desired Window Title String, width and height
* @param strWNDTitle The Window Title String
* @param iWidth The width of the window to draw
* @param iHeight The height of the window to draw
* @param wnd_Flags 0, or one or more SDL_WindowFlags OR'd together to determine how the window is shown
=======================================================================================================
*/
bool cSDL2WNDManager::initWND(string strWNDTitle, int iWidth, int iHeight, Uint32 wnd_Flags)
{
bool wndCreated = createSDLWnd(strWNDTitle, iWidth, iHeight, wnd_Flags);
return wndCreated;
}
void cSDL2WNDManager::CheckSDLError(int line = -1)
{
string error = SDL_GetError();
if (error != "")
{
cout << "SLD Error : " << error << std::endl;
if (line != -1)
cout << "\nLine : " << line << std::endl;
SDL_ClearError();
}
}
bool cSDL2WNDManager::createSDLWnd(string strWNDTitle, int iWidth, int iHeight, Uint32 wnd_Flags)
{
// Initialize SDL's Video subsystem
if (SDL_Init(SDL_INIT_VIDEO) < 0)
{
cout << "Failed to init SDL\n";
return false;
}
mainWindow = SDL_CreateWindow(strWNDTitle.c_str(), SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
iWidth, iHeight, wnd_Flags);
// Check that everything worked out okay
if (!mainWindow)
{
cout << "Unable to create window\n";
CheckSDLError(__LINE__);
return false;
}
else
{
// Get the renderer
theRenderer = SDL_CreateRenderer(mainWindow, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC);
if (theRenderer != 0)
{
std::cout << "Renderer creation succeeded" << std::endl;
SDL_SetRenderDrawColor(theRenderer, 0, 0, 100, 255);
}
else
{
std::cout << "Renderer creation failed" << std::endl;
return false;
}
}
return true;
}
SDL_Window* cSDL2WNDManager::getSDLWindow()
{
return mainWindow;
}
SDL_GLContext cSDL2WNDManager::getSDL_GLContext()
{
return mainContext;
}
SDL_Renderer* cSDL2WNDManager::getSDLRenderer()
{
return theRenderer;
}