source: opengl-game/game-gui-sdl.cpp@ d5f2b42

feature/imgui-sdl points-test
Last change on this file since d5f2b42 was d5f2b42, checked in by Dmitry Portnoy <dmitry.portnoy@…>, 5 years ago

Create a generic GetError() function in game-gui that returns the last error returned by a call to some other function in game-gui

  • Property mode set to 100644
File size: 2.0 KB
Line 
1#include "game-gui-sdl.hpp"
2
3string GameGui_SDL::s_errorMessage;
4
5string& GameGui_SDL::GetError() {
6 GameGui_SDL::s_errorMessage = SDL_GetError();
7
8 return GameGui_SDL::s_errorMessage;
9}
10
11bool 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
33void GameGui_SDL::Shutdown() {
34 SDL_Quit();
35}
36
37void* 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
48void 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
55bool 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
62vector<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
72void GameGui_SDL::GetWindowSize(int* width, int* height) {
73 SDL_GetWindowSize(window, width, height);
74}
Note: See TracBrowser for help on using the repository browser.