source: opengl-game/game-gui-sdl.cpp@ 17714b8

feature/imgui-sdl points-test
Last change on this file since 17714b8 was 5f3dba8, checked in by Dmitry Portnoy <dmp1488@…>, 5 years ago

Create a transparent texture in SDL and render some sample images and shapes onto it

  • Property mode set to 100644
File size: 2.0 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
49bool GameGui_SDL::CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {
50 return SDL_Vulkan_CreateSurface(window, instance, surface) ?
51 RTWO_SUCCESS : RTWO_ERROR;
52}
53
54vector<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
64void GameGui_SDL::GetWindowSize(int* width, int* height) {
65 SDL_GetWindowSize(window, width, height);
66}
Note: See TracBrowser for help on using the repository browser.