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