Changeset 7fc5e27 in opengl-game
- Timestamp:
- Sep 3, 2019, 7:07:39 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- b6e60b4
- Parents:
- 1ce9afe
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
game-gui-glfw.cpp
r1ce9afe r7fc5e27 11 11 bool GameGui_GLFW::s_keyDown[NUM_KEYS]; 12 12 13 string& GameGui_GLFW:: GetError() {13 string& GameGui_GLFW::getError() { 14 14 return GameGui_GLFW::s_errorMessage; 15 15 } 16 16 17 bool GameGui_GLFW:: Init() {17 bool GameGui_GLFW::init() { 18 18 GameGui_GLFW::s_errorMessage = "No error"; 19 19 glfwSetErrorCallback(glfw_error_callback); 20 21 windowWidth = -1; 22 windowHeight = -1; 20 23 21 24 return glfwInit() == GLFW_TRUE ? RTWO_SUCCESS : RTWO_ERROR; 22 25 } 23 26 24 void GameGui_GLFW:: Shutdown() {27 void GameGui_GLFW::shutdown() { 25 28 glfwTerminate(); 26 29 } 27 30 28 void* GameGui_GLFW:: CreateWindow(const string& title, unsigned int width, unsignedint height, bool fullscreen) {31 void* GameGui_GLFW::createWindow(const string& title, int width, int height, bool fullscreen) { 29 32 GLFWwindow* window = nullptr; 30 33 GLFWmonitor* mon = nullptr; … … 49 52 const GLFWvidmode* vmode = glfwGetVideoMode(mon); 50 53 51 width = vmode->width; 52 height = vmode->height; 53 54 // TODO: Should probably enable some way to retrieve this from outside this class 55 // and print it out there 56 cout << "Fullscreen resolution " << vmode->width << "x" << vmode->height << endl; 54 windowWidth = vmode->width; 55 windowHeight = vmode->height; 56 } else { 57 windowWidth = width; 58 windowHeight = height; 57 59 } 58 60 59 window = glfwCreateWindow(wi dth, height, title.c_str(), mon, nullptr);61 window = glfwCreateWindow(windowWidth, windowHeight, title.c_str(), mon, nullptr); 60 62 //glfwMakeContextCurrent(window); 61 63 … … 68 70 } 69 71 70 void GameGui_GLFW:: DestroyWindow() {72 void GameGui_GLFW::destroyWindow() { 71 73 // TODO: This function can throw some errors. They should be handled 72 74 glfwDestroyWindow(window); … … 75 77 #ifdef GAMEGUI_INCLUDE_VULKAN 76 78 77 bool GameGui_GLFW:: CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {79 bool GameGui_GLFW::createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) { 78 80 return glfwCreateWindowSurface(instance, window, nullptr, surface) == VK_SUCCESS ? 79 81 RTWO_SUCCESS : RTWO_ERROR; … … 82 84 #endif 83 85 84 vector<const char*> GameGui_GLFW:: GetRequiredExtensions() {86 vector<const char*> GameGui_GLFW::getRequiredExtensions() { 85 87 uint32_t glfwExtensionCount = 0; 86 88 const char** glfwExtensions; … … 93 95 } 94 96 95 void GameGui_GLFW::GetWindowSize(int* width, int* height) { 96 glfwGetFramebufferSize(window, width, height); 97 void GameGui_GLFW::getWindowSize(int* width, int* height) { 98 // This function segfaults on OSX, check other platforms 99 //glfwGetFramebufferSize(window, width, height); 100 101 *width = windowWidth; 102 *height = windowHeight; 97 103 } 98 104 -
game-gui-glfw.hpp
r1ce9afe r7fc5e27 21 21 static bool s_keyDown[NUM_KEYS]; 22 22 23 string& GetError();23 string& getError(); 24 24 25 bool Init();26 void Shutdown();25 bool init(); 26 void shutdown(); 27 27 28 void* CreateWindow(const string& title, unsigned int width, unsignedint height, bool fullscreen);29 void DestroyWindow();28 void* createWindow(const string& title, int width, int height, bool fullscreen); 29 void destroyWindow(); 30 30 31 31 #ifdef GAMEGUI_INCLUDE_VULKAN 32 bool CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface);32 bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface); 33 33 #endif 34 34 35 vector<const char*> GetRequiredExtensions();36 void GetWindowSize(int* width, int* height);35 vector<const char*> getRequiredExtensions(); 36 void getWindowSize(int* width, int* height); 37 37 38 38 private: 39 39 GLFWwindow* window; 40 41 int windowWidth, windowHeight; 40 42 }; 41 43 -
game-gui-sdl.cpp
r1ce9afe r7fc5e27 5 5 string GameGui_SDL::s_errorMessage; 6 6 7 string& GameGui_SDL:: GetError() {7 string& GameGui_SDL::getError() { 8 8 GameGui_SDL::s_errorMessage = SDL_GetError(); 9 9 … … 11 11 } 12 12 13 bool GameGui_SDL:: Init() {13 bool GameGui_SDL::init() { 14 14 // may want to define SDL_INIT_NOPARACHUTE when I start handling crashes since it 15 15 // prevents SDL from setting up its own handlers for SIG_SEGV and stuff like that … … 33 33 } 34 34 35 void GameGui_SDL:: Shutdown() {35 void GameGui_SDL::shutdown() { 36 36 SDL_Quit(); 37 37 } 38 38 39 void* GameGui_SDL::CreateWindow(const string& title, unsigned int width, unsigned int height, bool fullscreen) { 40 cout << "About to go fullscreen in SDL..." << endl; 41 39 void* GameGui_SDL::createWindow(const string& title, int width, int height, bool fullscreen) { 42 40 // TODO: Make an OpenGL version of the SDL_CreateWindow call as well 43 41 44 42 // On Apple's OS X you must set the NSHighResolutionCapable Info.plist property to YES, 45 43 // otherwise you will not receive a High DPI OpenGL canvas. 44 45 uint32_t flags = SDL_WINDOW_VULKAN; 46 47 flags |= fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : SDL_WINDOW_RESIZABLE; 48 46 49 window = SDL_CreateWindow(title.c_str(), 47 50 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 48 width, height, 49 SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); 51 width, height, flags); 50 52 51 53 return window; 52 54 } 53 55 54 void GameGui_SDL:: DestroyWindow() {56 void GameGui_SDL::destroyWindow() { 55 57 // TODO: This function can throw some errors. They should be handled 56 58 SDL_DestroyWindow(window); … … 59 61 #ifdef GAMEGUI_INCLUDE_VULKAN 60 62 61 bool GameGui_SDL:: CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) {63 bool GameGui_SDL::createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) { 62 64 return SDL_Vulkan_CreateSurface(window, instance, surface) ? 63 65 RTWO_SUCCESS : RTWO_ERROR; … … 66 68 #endif 67 69 68 vector<const char*> GameGui_SDL:: GetRequiredExtensions() {70 vector<const char*> GameGui_SDL::getRequiredExtensions() { 69 71 uint32_t extensionCount = 0; 70 72 SDL_Vulkan_GetInstanceExtensions(window, &extensionCount, nullptr); … … 76 78 } 77 79 78 void GameGui_SDL:: GetWindowSize(int* width, int* height) {80 void GameGui_SDL::getWindowSize(int* width, int* height) { 79 81 SDL_GetWindowSize(window, width, height); 80 82 } -
game-gui-sdl.hpp
r1ce9afe r7fc5e27 11 11 class GameGui_SDL : public GameGui { 12 12 public: 13 string& GetError();13 string& getError(); 14 14 15 bool Init();16 void Shutdown();15 bool init(); 16 void shutdown(); 17 17 18 void* CreateWindow(const string& title, unsigned int width, unsignedint height, bool fullscreen);19 void DestroyWindow();18 void* createWindow(const string& title, int width, int height, bool fullscreen); 19 void destroyWindow(); 20 20 21 21 #ifdef GAMEGUI_INCLUDE_VULKAN 22 bool CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface);22 bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface); 23 23 #endif 24 24 25 vector<const char*> GetRequiredExtensions();26 void GetWindowSize(int* width, int* height);25 vector<const char*> getRequiredExtensions(); 26 void getWindowSize(int* width, int* height); 27 27 28 28 private: -
game-gui.hpp
r1ce9afe r7fc5e27 18 18 virtual ~GameGui() {}; 19 19 20 virtual string& GetError() = 0;20 virtual string& getError() = 0; 21 21 22 virtual bool Init() = 0;23 virtual void Shutdown() = 0;22 virtual bool init() = 0; 23 virtual void shutdown() = 0; 24 24 25 virtual void* CreateWindow(const string& title, unsigned int width, unsignedint height, bool fullscreen) = 0;26 virtual void DestroyWindow() = 0;25 virtual void* createWindow(const string& title, int width, int height, bool fullscreen) = 0; 26 virtual void destroyWindow() = 0; 27 27 28 28 #ifdef GAMEGUI_INCLUDE_VULKAN 29 virtual bool CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) = 0;29 virtual bool createVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) = 0; 30 30 #endif 31 31 32 virtual vector<const char*> GetRequiredExtensions() = 0;33 virtual void GetWindowSize(int* width, int* height) = 0;32 virtual vector<const char*> getRequiredExtensions() = 0; 33 virtual void getWindowSize(int* width, int* height) = 0; 34 34 }; 35 35 -
vulkan-ref.cpp
r1ce9afe r7fc5e27 19 19 #include <chrono> 20 20 21 #include "consts.hpp" 21 22 #include "utils.h" 22 23 … … 226 227 // TODO: Put all fonts, textures, and images in the assets folder 227 228 228 if (gui-> Init() == RTWO_ERROR) {229 if (gui->init() == RTWO_ERROR) { 229 230 cout << "UI library could not be initialized!" << endl; 230 231 cout << SDL_GetError() << endl; … … 233 234 cout << "GUI init succeeded" << endl; 234 235 235 window = (SDL_Window*) gui-> CreateWindow("Vulkan Game", SCREEN_WIDTH, SCREEN_HEIGHT);236 window = (SDL_Window*) gui->createWindow("Vulkan Game", SCREEN_WIDTH, SCREEN_HEIGHT, false); 236 237 if (window == nullptr) { 237 238 cout << "Window could not be created!" << endl; … … 459 460 460 461 vector<const char*> getRequiredExtensions() { 461 vector<const char*> extensions = gui-> GetRequiredExtensions();462 vector<const char*> extensions = gui->getRequiredExtensions(); 462 463 463 464 if (enableValidationLayers) { … … 488 489 489 490 void createSurface() { 490 if (gui-> CreateVulkanSurface(instance, &surface) == RTWO_ERROR) {491 if (gui->createVulkanSurface(instance, &surface) == RTWO_ERROR) { 491 492 throw runtime_error("failed to create window surface!"); 492 493 } … … 710 711 else { 711 712 int width, height; 712 gui-> GetWindowSize(&width, &height);713 gui->getWindowSize(&width, &height); 713 714 714 715 VkExtent2D actualExtent = { … … 1812 1813 int width = 0, height = 0; 1813 1814 1814 gui-> GetWindowSize(&width, &height);1815 gui->getWindowSize(&width, &height); 1815 1816 1816 1817 while (width == 0 || height == 0 || 1817 1818 (SDL_GetWindowFlags(window) & SDL_WINDOW_MINIMIZED) != 0) { 1818 1819 SDL_WaitEvent(nullptr); 1819 gui-> GetWindowSize(&width, &height);1820 gui->getWindowSize(&width, &height); 1820 1821 } 1821 1822 … … 1908 1909 gRenderer = nullptr; 1909 1910 1910 gui-> DestroyWindow();1911 gui-> Shutdown();1911 gui->destroyWindow(); 1912 gui->shutdown(); 1912 1913 delete gui; 1913 1914 }
Note:
See TracChangeset
for help on using the changeset viewer.