Changeset 0e6ecf3 in opengl-game
- Timestamp:
- Jul 19, 2019, 8:50:06 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 8667f76
- Parents:
- 75108ef
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
game-gui-sdl.cpp
r75108ef r0e6ecf3 1 1 #include "game-gui-sdl.hpp" 2 3 #include <SDL2/SDL.h>4 5 #include <iostream>6 7 using namespace std;8 2 9 3 bool GameGui_SDL::Init() { … … 22 16 SDL_Quit(); 23 17 } 18 19 void* 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 30 void GameGui_SDL::DestroyWindow() { 31 // TODO: This function can throw some errors. They should be handled 32 SDL_DestroyWindow(window); 33 } 34 35 bool GameGui_SDL::CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) { 36 return SDL_Vulkan_CreateSurface(window, instance, surface) ? 37 RTWO_SUCCESS : RTWO_ERROR; 38 } -
game-gui-sdl.hpp
r75108ef r0e6ecf3 1 #ifndef _GAME_GUI_SDL_H 2 #define _GAME_GUI_SDL_H 3 1 4 #include "game-gui.hpp" 5 6 #include <SDL2/SDL.h> 7 #include <SDL2/SDL_vulkan.h> 2 8 3 9 class GameGui_SDL : public GameGui { … … 5 11 bool Init(); 6 12 void Shutdown(); 13 14 void* CreateWindow(const string& title, unsigned int width, unsigned int height); 15 void DestroyWindow(); 16 17 bool CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface); 18 19 private: 20 SDL_Window* window; 7 21 }; 22 23 #endif // _GAME_GUI_SDL_H -
game-gui.hpp
r75108ef r0e6ecf3 1 #ifndef _GAME_GUI_H 2 #define _GAME_GUI_H 3 4 #include <vulkan/vulkan.h> 5 6 #include <string> 7 8 using namespace std; 9 1 10 #define RTWO_SUCCESS true 2 11 #define RTWO_ERROR false … … 8 17 virtual bool Init() = 0; 9 18 virtual void Shutdown() = 0; 19 20 virtual void* CreateWindow(const string& title, unsigned int width, unsigned int height) = 0; 21 virtual void DestroyWindow() = 0; 22 23 virtual bool CreateVulkanSurface(VkInstance instance, VkSurfaceKHR* surface) = 0; 10 24 }; 25 26 #endif // _GAME_GUI_H -
makefile
r75108ef r0e6ecf3 42 42 endif 43 43 44 LIBS = `pkg-config --static --libs sdl2 `44 LIBS = `pkg-config --static --libs sdl2 glfw3` 45 45 ifeq ($(OS),Darwin) 46 46 LIBS := $(VULKAN_SDK_PATH)/lib/libvulkan.dylib $(LIBS) … … 52 52 LIB_FLAGS = $(LIB_PATHS) $(LIBS) 53 53 54 vulkangame: vulkan-game.cpp game-gui-sdl.cpp 54 vulkangame: vulkan-game.cpp game-gui-sdl.cpp game-gui-glfw.cpp 55 55 $(CC) $(CXX_FLAGS) -o $@ $^ $(LIB_FLAGS) 56 56 -
vulkan-game.cpp
r75108ef r0e6ecf3 1 #include <vulkan/vulkan.h> 2 3 #include <SDL2/SDL.h> 4 #include <SDL2/SDL_vulkan.h> 1 #include "game-gui-glfw.hpp" 2 3 #include "game-gui-sdl.hpp" 5 4 6 5 //#define _USE_MATH_DEFINES // Will be needed when/if I need to # include <cmath> … … 11 10 #include <glm/mat4x4.hpp> 12 11 12 #include <fstream> 13 13 #include <iostream> 14 #include <optional> 15 #include <set> 14 16 #include <vector> 15 #include <set>16 #include <stdexcept>17 #include <cstdlib>18 #include <optional>19 #include <algorithm>20 #include <fstream>21 22 #include "game-gui-sdl.hpp"23 17 24 18 using namespace std; … … 137 131 return RTWO_ERROR; 138 132 } else { 139 // On Apple's OS X you must set the NSHighResolutionCapable Info.plist property to YES, 140 // otherwise you will not receive a High DPI OpenGL canvas. 141 142 // TODO: Move this into some generic method in game-gui-sdl 143 window = SDL_CreateWindow("Vulkan Game", 144 SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 145 SCREEN_WIDTH, SCREEN_HEIGHT, 146 SDL_WINDOW_VULKAN | SDL_WINDOW_SHOWN | SDL_WINDOW_RESIZABLE); 133 window = (SDL_Window*) gui->CreateWindow("Vulkan Game", SCREEN_WIDTH, SCREEN_HEIGHT); 147 134 148 135 if (window == nullptr) { … … 274 261 } 275 262 276 if ( !SDL_Vulkan_CreateSurface(window, instance, &surface)) {263 if (gui->CreateVulkanSurface(instance, &surface) == RTWO_ERROR) { 277 264 throw runtime_error("failed to create window surface!"); 278 265 } 279 280 /*281 if (glfwCreateWindowSurface(instance, window, nullptr, &surface) != VK_SUCCESS) {282 throw runtime_error("failed to create window surface!");283 }284 */285 266 } 286 267 … … 1014 995 vkDestroyInstance(instance, nullptr); 1015 996 1016 // TODO: Move this into some generic method in game-gui-sdl 1017 SDL_DestroyWindow(window); 1018 997 gui->DestroyWindow(); 1019 998 gui->Shutdown(); 1020 999 delete gui; … … 1029 1008 1030 1009 return VK_FALSE; 1031 }1010 } 1032 1011 1033 1012 static vector<char> readFile(const string& filename) {
Note:
See TracChangeset
for help on using the changeset viewer.