Changeset e1f88a9 in opengl-game
- Timestamp:
- Jun 10, 2020, 2:36:24 AM (5 years ago)
- Branches:
- feature/imgui-sdl, master
- Children:
- 699e83a
- Parents:
- 4e705d6
- Files:
-
- 9 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
consts.hpp
r4e705d6 re1f88a9 13 13 constexpr unsigned char GUI_FLAGS_WINDOW_FULLSCREEN { 1 << 0 }; 14 14 15 enum ScreenType { 16 SCREEN_MAIN, 17 SCREEN_GAME 18 }; 19 15 20 #endif // _RTWO_CONSTS_H -
game-gui.hpp
r4e705d6 re1f88a9 10 10 11 11 using namespace std; 12 13 // TODO: See if it makes sense to combine this with the files in the gui folder 12 14 13 15 enum EventType { … … 54 56 }; 55 57 58 // TODO: Switch from union to std::variant 59 56 60 union UIEvent { 57 61 EventType type; -
makefile
r4e705d6 re1f88a9 45 45 endif 46 46 47 LIBS = `pkg-config --static --libs sdl2 sdl2_image sdl2_ttf `47 LIBS = `pkg-config --static --libs sdl2 sdl2_image sdl2_ttf sdl2_gfx` 48 48 ifeq ($(OS),Darwin) 49 49 LIBS := $(VULKAN_SDK_PATH)/lib/libvulkan.dylib $(LIBS) … … 51 51 ifeq ($(OS),Linux) 52 52 LIBS = `pkg-config --static --libs sdl2` 53 LIBS := -lvulkan $(LIBS) -lSDL2_image -lSDL2_ttf # TODO: figure out how to statically link these, ideally using pkg-config53 LIBS := -lvulkan $(LIBS) -lSDL2_image -lSDL2_ttf -lSDL2_gfx # TODO: figure out how to statically link these, ideally using pkg-config 54 54 endif 55 55 … … 59 59 $(CC) $(CXX_FLAGS) -o $@ $^ $(LIB_FLAGS) -DGAMEGUI_INCLUDE_VULKAN 60 60 61 SRC_FILES = main-vulkan.cpp vulkan-game.cpp crash-logger.cpp logger.cpp vulkan-utils.cpp utils.cpp game-gui-sdl.cpp 62 HEADER_FILES = vulkan-game.hpp crash-logger.hpp logger.hpp vulkan-utils.hpp utils.hpp game-gui-sdl.hpp game-gui.hpp graphics-pipeline_vulkan.hpp 61 GUI_SRC_FILES = gui/screen.cpp gui/main-screen.cpp gui/ui-element.cpp gui/button.cpp 62 GUI_HEADER_FILES = gui/screen.hpp gui/main-screen.hpp gui/ui-element.hpp gui/button.hpp 63 64 SRC_FILES = main-vulkan.cpp vulkan-game.cpp crash-logger.cpp logger.cpp vulkan-utils.cpp utils.cpp game-gui-sdl.cpp $(GUI_SRC_FILES) 65 HEADER_FILES = vulkan-game.hpp crash-logger.hpp logger.hpp vulkan-utils.hpp utils.hpp game-gui-sdl.hpp game-gui.hpp graphics-pipeline_vulkan.hpp $(GUI_HEADER_FILES) 63 66 64 67 vulkangame: $(SRC_FILES) $(HEADER_FILES) -
vulkan-game.cpp
r4e705d6 re1f88a9 46 46 } 47 47 48 screens[SCREEN_MAIN] = new MainScreen(*renderer, *this); 49 50 currentScreen = screens[SCREEN_MAIN]; 51 48 52 initVulkan(); 49 53 mainLoop(); … … 51 55 52 56 close_log(); 57 } 58 59 void VulkanGame::goToScreen(Screen* screen) { 60 currentScreen = screen; 61 currentScreen->init(); 62 63 recreateSwapChain(); 64 } 65 66 void VulkanGame::quitGame() { 67 this->quit = true; 53 68 } 54 69 … … 121 136 SDL_SetRenderTarget(renderer, uiOverlay); 122 137 138 // TODO: Print the filename of the font in the error message 139 123 140 font = TTF_OpenFont("assets/fonts/lazy.ttf", 28); 124 141 if (font == nullptr) { … … 157 174 158 175 SDL_FreeSurface(imageSDLSurface); 176 177 proggyFont = TTF_OpenFont("assets/fonts/ProggyClean.ttf", 16); 178 if (proggyFont == nullptr) { 179 cout << "Failed to load proggy font! SDL_ttf Error: " << TTF_GetError() << endl; 180 return RTWO_ERROR; 181 } 159 182 160 183 return RTWO_SUCCESS; … … 640 663 void VulkanGame::mainLoop() { 641 664 UIEvent e; 642 boolquit = false;665 this->quit = false; 643 666 644 667 this->startTime = high_resolution_clock::now(); … … 647 670 lastSpawn_asteroid = curTime; 648 671 649 while (! quit) {672 while (!this->quit) { 650 673 651 674 this->prevTime = curTime; … … 659 682 case UI_EVENT_QUIT: 660 683 cout << "Quit event detected" << endl; 661 quit = true;684 this->quit = true; 662 685 break; 663 686 case UI_EVENT_WINDOW: … … 675 698 676 699 if (e.key.keycode == SDL_SCANCODE_ESCAPE) { 677 quit = true;700 this->quit = true; 678 701 } else if (e.key.keycode == SDL_SCANCODE_SPACE) { 679 702 cout << "Adding a plane" << endl; … … 753 776 cout << "Unhandled UI event: " << e.type << endl; 754 777 } 778 779 currentScreen->handleEvent(e); 755 780 } 756 781 … … 787 812 } 788 813 789 renderUI(); 814 // renderUI(); 815 currentScreen->renderUI(); 816 817 // Copy the UI image to a vulkan texture 818 VulkanUtils::populateVulkanImageFromSDLTexture(device, physicalDevice, commandPool, uiOverlay, renderer, 819 sdlOverlayImage, graphicsQueue); 820 790 821 renderScene(); 791 822 } … … 1010 1041 } 1011 1042 1043 // TODO: Maybe move all/most of this to the base Screen class 1012 1044 void VulkanGame::renderScene() { 1013 1045 vkWaitForFences(device, 1, &inFlightFences[currentFrame], VK_TRUE, numeric_limits<uint64_t>::max()); … … 1111 1143 vkDestroyInstance(instance, nullptr); 1112 1144 1145 delete screens[SCREEN_MAIN]; 1146 1113 1147 // TODO: Check if any of these functions accept null parameters 1114 1148 // If they do, I don't need to check for that … … 1126 1160 TTF_CloseFont(font); 1127 1161 font = nullptr; 1162 1163 if (proggyFont != nullptr) { 1164 TTF_CloseFont(proggyFont); 1165 proggyFont = nullptr; 1166 } 1128 1167 1129 1168 if (uiOverlay != nullptr) { … … 1582 1621 vkCmdBeginRenderPass(commandBuffers[i], &renderPassInfo, VK_SUBPASS_CONTENTS_INLINE); 1583 1622 1623 /* 1584 1624 modelPipeline.createRenderCommands(commandBuffers[i], i); 1585 1625 shipPipeline.createRenderCommands(commandBuffers[i], i); … … 1590 1630 // Always render this pipeline last 1591 1631 overlayPipeline.createRenderCommands(commandBuffers[i], i); 1632 */ 1633 1634 currentScreen->createRenderCommands(commandBuffers[i], i); 1592 1635 1593 1636 vkCmdEndRenderPass(commandBuffers[i]); -
vulkan-game.hpp
r4e705d6 re1f88a9 3 3 4 4 #include <chrono> 5 #include <map> 5 6 6 7 #define GLM_FORCE_RADIANS … … 16 17 #include "game-gui-sdl.hpp" 17 18 19 #include "gui/screen.hpp" 20 #include "gui/main-screen.hpp" 21 18 22 using namespace glm; 19 23 using namespace std::chrono; 20 21 // TODO: Switch from union to std::variant22 24 23 25 #ifdef NDEBUG … … 195 197 void run(int width, int height, unsigned char guiFlags); 196 198 199 void goToScreen(Screen* screen); 200 void quitGame(); 201 202 map<ScreenType, Screen*> screens; 203 Screen* currentScreen; 204 205 TTF_Font* proggyFont; 206 197 207 GraphicsPipeline_Vulkan<OverlayVertex, void*> overlayPipeline; 198 208 … … 219 229 const int EXPLOSION_PARTICLE_COUNT = 300; 220 230 const vec3 LASER_COLOR = vec3(0.2f, 1.0f, 0.2f); 231 232 bool quit; 221 233 222 234 vec3 cam_pos;
Note:
See TracChangeset
for help on using the changeset viewer.