blob: c3134b4ba18a9eb2ef20b558bebac142821984b7 (
plain)
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
|
#include "applicationBase.h"
#include "imgui_wrap.h"
#include <SDL2/SDL.h>
#include <stdexcept>
ApplicationBase::ApplicationBase()
{
initSDL();
initImGUI();
}
void
ApplicationBase::initSDL() const
{
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) {
throw std::runtime_error(SDL_GetError());
}
const auto setGlAttribute = [](auto attr, auto value) {
if (SDL_GL_SetAttribute(attr, value) < 0) {
throw std::runtime_error(SDL_GetError());
}
};
setGlAttribute(SDL_GL_RED_SIZE, 8);
setGlAttribute(SDL_GL_GREEN_SIZE, 8);
setGlAttribute(SDL_GL_BLUE_SIZE, 8);
setGlAttribute(SDL_GL_ALPHA_SIZE, 8);
setGlAttribute(SDL_GL_BUFFER_SIZE, 32);
setGlAttribute(SDL_GL_DEPTH_SIZE, 16);
setGlAttribute(SDL_GL_DOUBLEBUFFER, 1);
setGlAttribute(SDL_GL_SHARE_WITH_CURRENT_CONTEXT, 1);
}
void
ApplicationBase::initImGUI() const
{
puts(__PRETTY_FUNCTION__);
// Setup Dear ImGui context
IMGUI_CHECKVERSION();
ImGui::CreateContext();
ImGuiIO & io = ImGui::GetIO();
io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad; // Enable Gamepad Controls
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable viewports
}
ApplicationBase::~ApplicationBase()
{
SDL_Quit();
ImGui::DestroyContext();
}
|