source: opengl-game/game-gui-sdl.cpp@ 99d44b2

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

Rename vulkan-game.cpp to vulkan-ref.cpp and define the GAMEGUI_INCLUDE_VULKAN preprocessor directive to control whether the gui-game classes build with Vulkan support

  • Property mode set to 100644
File size: 2.1 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 // 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
29void GameGui_SDL::Shutdown() {
30 SDL_Quit();
31}
32
33void* 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
44void GameGui_SDL::DestroyWindow() {
45 // TODO: This function can throw some errors. They should be handled
46 SDL_DestroyWindow(window);
47}
48
49#ifdef GAMEGUI_INCLUDE_VULKAN
50
51bool GameGui_SDL::CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {
52 return SDL_Vulkan_CreateSurface(window, instance, surface) ?
53 RTWO_SUCCESS : RTWO_ERROR;
54}
55
56#endif
57
58vector<const char*> GameGui_SDL::GetRequiredExtensions() {
59 uint32_t extensionCount = 0;
60 SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, nullptr);
61
62 vector<const char*> extensions(extensionCount);
63 SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, extensions.data());
64
65 return extensions;
66}
67
68void GameGui_SDL::GetWindowSize(int* width, int* height) {
69 SDL_GetWindowSize(window, width, height);
70}
Note: See TracBrowser for help on using the repository browser.