Changeset e1f88a9 in opengl-game for vulkan-game.cpp
- Timestamp:
- Jun 10, 2020, 2:36:24 AM (4 years ago)
- Branches:
- feature/imgui-sdl, master
- Children:
- 699e83a
- Parents:
- 4e705d6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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]);
Note:
See TracChangeset
for help on using the changeset viewer.