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