[f898c5f] | 1 | #include "game-gui-sdl.hpp"
|
---|
| 2 |
|
---|
[d5f2b42] | 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 |
|
---|
[f898c5f] | 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 |
|
---|
[d5f2b42] | 15 | GameGui_SDL::s_errorMessage = "No error";
|
---|
[f898c5f] | 16 |
|
---|
[5f3dba8] | 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;
|
---|
[f898c5f] | 31 | }
|
---|
| 32 |
|
---|
| 33 | void GameGui_SDL::Shutdown() {
|
---|
| 34 | SDL_Quit();
|
---|
[826df16] | 35 | }
|
---|
[0e6ecf3] | 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 |
|
---|
[4eb4d0a] | 53 | #ifdef GAMEGUI_INCLUDE_VULKAN
|
---|
| 54 |
|
---|
[0e6ecf3] | 55 | bool GameGui_SDL::CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {
|
---|
| 56 | return SDL_Vulkan_CreateSurface(window, instance, surface) ?
|
---|
| 57 | RTWO_SUCCESS : RTWO_ERROR;
|
---|
| 58 | }
|
---|
[8667f76] | 59 |
|
---|
[4eb4d0a] | 60 | #endif
|
---|
| 61 |
|
---|
[8667f76] | 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 | }
|
---|