source: opengl-game/game-gui-sdl.cpp@ 1ce9afe

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

Add a fullscreen flag to GameGui::CreateWindow and implement fullscreen functionality and the ability to detect key presses in openglgame

  • Property mode set to 100644
File size: 2.1 KB
Line 
1#include "game-gui-sdl.hpp"
2
3#include "consts.hpp"
4
5string GameGui_SDL::s_errorMessage;
6
7string& GameGui_SDL::GetError() {
8 GameGui_SDL::s_errorMessage = SDL_GetError();
9
10 return GameGui_SDL::s_errorMessage;
11}
12
13bool GameGui_SDL::Init() {
14 // may want to define SDL_INIT_NOPARACHUTE when I start handling crashes since it
15 // prevents SDL from setting up its own handlers for SIG_SEGV and stuff like that
16
17 GameGui_SDL::s_errorMessage = "No error";
18
19 if (SDL_Init(SDL_INIT_EVERYTHING) < 0) {
20 return RTWO_ERROR;
21 }
22
23 int imgFlags = IMG_INIT_PNG;
24 if (!(IMG_Init(imgFlags) & imgFlags)) {
25 return RTWO_ERROR;
26 }
27
28 if (TTF_Init() == -1) {
29 return RTWO_ERROR;
30 }
31
32 return RTWO_SUCCESS;
33}
34
35void GameGui_SDL::Shutdown() {
36 SDL_Quit();
37}
38
39void* GameGui_SDL::CreateWindow(const string& title, unsigned int width, unsigned int height, bool fullscreen) {
40 cout << "About to go fullscreen in SDL..." << endl;
41
42 // TODO: Make an OpenGL version of the SDL_CreateWindow call as well
43
44 // On Apple's OS X you must set the NSHighResolutionCapable Info.plist property to YES,
45 // otherwise you will not receive a High DPI OpenGL canvas.
46 window = SDL_CreateWindow(title.c_str(),
47 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED,
48 width, height,
49 SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE);
50
51 return window;
52}
53
54void GameGui_SDL::DestroyWindow() {
55 // TODO: This function can throw some errors. They should be handled
56 SDL_DestroyWindow(window);
57}
58
59#ifdef GAMEGUI_INCLUDE_VULKAN
60
61bool GameGui_SDL::CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {
62 return SDL_Vulkan_CreateSurface(window, instance, surface) ?
63 RTWO_SUCCESS : RTWO_ERROR;
64}
65
66#endif
67
68vector<const char*> GameGui_SDL::GetRequiredExtensions() {
69 uint32_t extensionCount = 0;
70 SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, nullptr);
71
72 vector<const char*> extensions(extensionCount);
73 SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, extensions.data());
74
75 return extensions;
76}
77
78void GameGui_SDL::GetWindowSize(int* width, int* height) {
79 SDL_GetWindowSize(window, width, height);
80}
Note: See TracBrowser for help on using the repository browser.