1 | #include "game-gui-sdl.hpp"
|
---|
2 |
|
---|
3 | string GameGui_SDL::s_errorMessage;
|
---|
4 |
|
---|
5 | string& GameGui_SDL::GetError() {
|
---|
6 | GameGui_SDL::s_errorMessage = SDL_GetError();
|
---|
7 |
|
---|
8 | return GameGui_SDL::s_errorMessage;
|
---|
9 | }
|
---|
10 |
|
---|
11 | bool GameGui_SDL::Init() {
|
---|
12 | // may want to define SDL_INIT_NOPARACHUTE when I start handling crashes since it
|
---|
13 | // prevents SDL from setting up its own handlers for SIG_SEGV and stuff like that
|
---|
14 |
|
---|
15 | GameGui_SDL::s_errorMessage = "No error";
|
---|
16 |
|
---|
17 | if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
|
---|
18 | return RTWO_ERROR;
|
---|
19 | }
|
---|
20 |
|
---|
21 | int imgFlags = IMG_INIT_PNG;
|
---|
22 | if (!(IMG_Init(imgFlags) & imgFlags)) {
|
---|
23 | return RTWO_ERROR;
|
---|
24 | }
|
---|
25 |
|
---|
26 | if (TTF_Init() == -1) {
|
---|
27 | return RTWO_ERROR;
|
---|
28 | }
|
---|
29 |
|
---|
30 | return RTWO_SUCCESS;
|
---|
31 | }
|
---|
32 |
|
---|
33 | void GameGui_SDL::Shutdown() {
|
---|
34 | SDL_Quit();
|
---|
35 | }
|
---|
36 |
|
---|
37 | void* GameGui_SDL::CreateWindow(const string& title, unsigned int width, unsigned int height) {
|
---|
38 | // On Apple's OS X you must set the NSHighResolutionCapable Info.plist property to YES,
|
---|
39 | // otherwise you will not receive a High DPI OpenGL canvas.
|
---|
40 | window = SDL_CreateWindow(title.c_str(),
|
---|
41 | SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
|
---|
42 | width, height,
|
---|
43 | SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
|
---|
44 |
|
---|
45 | return window;
|
---|
46 | }
|
---|
47 |
|
---|
48 | void GameGui_SDL::DestroyWindow() {
|
---|
49 | // TODO: This function can throw some errors. They should be handled
|
---|
50 | SDL_DestroyWindow(window);
|
---|
51 | }
|
---|
52 |
|
---|
53 | #ifdef GAMEGUI_INCLUDE_VULKAN
|
---|
54 |
|
---|
55 | bool GameGui_SDL::CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {
|
---|
56 | return SDL_Vulkan_CreateSurface(window, instance, surface) ?
|
---|
57 | RTWO_SUCCESS : RTWO_ERROR;
|
---|
58 | }
|
---|
59 |
|
---|
60 | #endif
|
---|
61 |
|
---|
62 | vector<const char*> GameGui_SDL::GetRequiredExtensions() {
|
---|
63 | uint32_t extensionCount = 0;
|
---|
64 | SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, nullptr);
|
---|
65 |
|
---|
66 | vector<const char*> extensions(extensionCount);
|
---|
67 | SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, extensions.data());
|
---|
68 |
|
---|
69 | return extensions;
|
---|
70 | }
|
---|
71 |
|
---|
72 | void GameGui_SDL::GetWindowSize(int* width, int* height) {
|
---|
73 | SDL_GetWindowSize(window, width, height);
|
---|
74 | }
|
---|