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

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

Move getWindowSize and getRequiredExtensions to the game gui

  • Property mode set to 100644
File size: 1.8 KB
Line 
1#include "game-gui-sdl.hpp"
2
3bool 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 return SDL_Init(SDL_INIT_EVERYTHING) < 0 ? RTWO_ERROR : RTWO_SUCCESS;
13}
14
15void GameGui_SDL::Shutdown() {
16 SDL_Quit();
17}
18
19void* GameGui_SDL::CreateWindow(const string& title, unsigned int width, unsigned int height) {
20 // On Apple's OS X you must set the NSHighResolutionCapable Info.plist property to YES,
21 // otherwise you will not receive a High DPI OpenGL canvas.
22 window = SDL_CreateWindow(title.c_str(),
23 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
24 width, height,
25 SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
26
27 return window;
28}
29
30void GameGui_SDL::DestroyWindow() {
31 // TODO: This function can throw some errors. They should be handled
32 SDL_DestroyWindow(window);
33}
34
35bool GameGui_SDL::CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {
36 return SDL_Vulkan_CreateSurface(window, instance, surface) ?
37 RTWO_SUCCESS : RTWO_ERROR;
38}
39
40vector<const char*> GameGui_SDL::GetRequiredExtensions() {
41 uint32_t extensionCount = 0;
42 SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, nullptr);
43
44 vector<const char*> extensions(extensionCount);
45 SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, extensions.data());
46
47 return extensions;
48}
49
50void GameGui_SDL::GetWindowSize(int* width, int* height) {
51 SDL_GetWindowSize(window, width, height);
52}
Note: See TracBrowser for help on using the repository browser.