Changeset 1f25a71 in opengl-game
- Timestamp:
- Nov 10, 2019, 5:40:12 PM (5 years ago)
- Branches:
- feature/imgui-sdl, master, points-test
- Children:
- 0ae182f
- Parents:
- cc4a8b5
- git-author:
- Dmitry Portnoy <dmitry.portnoy@…> (11/10/19 17:39:32)
- git-committer:
- Dmitry Portnoy <dmitry.portnoy@…> (11/10/19 17:40:12)
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
rcc4a8b5 r1f25a71 28 28 gui = nullptr; 29 29 window = nullptr; 30 font = nullptr; 31 fontSDLTexture = nullptr; 32 imageSDLTexture = nullptr; 30 33 31 34 currentFrame = 0; … … 102 105 103 106 SDL_VERSION(&sdlVersion); 107 108 cout << "SDL " << sdlVersion.major << "." << sdlVersion.minor << "." << sdlVersion.patch << endl; 109 110 font = TTF_OpenFont("assets/fonts/lazy.ttf", 28); 111 if (font == nullptr) { 112 cout << "Failed to load lazy font! SDL_ttf Error: " << TTF_GetError() << endl; 113 return RTWO_ERROR; 114 } 115 116 SDL_Surface* fontSDLSurface = TTF_RenderText_Solid(font, "Great success!", { 255, 255, 255 }); 117 if (fontSDLSurface == nullptr) { 118 cout << "Unable to render text surface! SDL_ttf Error: " << TTF_GetError() << endl; 119 return RTWO_ERROR; 120 } 121 122 fontSDLTexture = SDL_CreateTextureFromSurface(renderer, fontSDLSurface); 123 if (fontSDLTexture == nullptr) { 124 cout << "Unable to create texture from rendered text! SDL Error: " << SDL_GetError() << endl; 125 SDL_FreeSurface(fontSDLSurface); 126 return RTWO_ERROR; 127 } 128 129 SDL_FreeSurface(fontSDLSurface); 130 131 // TODO: Load a PNG instead 132 SDL_Surface* imageSDLSurface = SDL_LoadBMP("assets/images/spaceship.bmp"); 133 if (imageSDLSurface == nullptr) { 134 cout << "Unable to load image " << "spaceship.bmp" << "! SDL Error: " << SDL_GetError() << endl; 135 return RTWO_ERROR; 136 } 137 138 imageSDLTexture = SDL_CreateTextureFromSurface(renderer, imageSDLSurface); 139 if (imageSDLTexture == nullptr) { 140 cout << "Unable to create texture from BMP surface! SDL Error: " << SDL_GetError() << endl; 141 SDL_FreeSurface(imageSDLSurface); 142 return RTWO_ERROR; 143 } 144 145 SDL_FreeSurface(imageSDLSurface); 104 146 105 147 // In SDL 2.0.10 (currently, the latest), SDL_TEXTUREACCESS_TARGET is required to get a transparent overlay working … … 117 159 if (uiOverlay == nullptr) { 118 160 cout << "Unable to create blank texture! SDL Error: " << SDL_GetError() << endl; 161 return RTWO_ERROR; 119 162 } 120 163 if (SDL_SetTextureBlendMode(uiOverlay, SDL_BLENDMODE_BLEND) != 0) { 121 164 cout << "Unable to set texture blend mode! SDL Error: " << SDL_GetError() << endl; 165 return RTWO_ERROR; 122 166 } 123 167 … … 282 326 SDL_RenderFillRect(renderer, &rect); 283 327 328 rect = {10, 10, 0, 0}; 329 SDL_QueryTexture(fontSDLTexture, nullptr, nullptr, &(rect.w), &(rect.h)); 330 SDL_RenderCopy(renderer, fontSDLTexture, nullptr, &rect); 331 332 rect = {10, 80, 0, 0}; 333 SDL_QueryTexture(imageSDLTexture, nullptr, nullptr, &(rect.w), &(rect.h)); 334 SDL_RenderCopy(renderer, imageSDLTexture, nullptr, &rect); 335 284 336 SDL_SetRenderDrawColor(renderer, 0x00, 0x00, 0xFF, 0xFF); 285 337 SDL_RenderDrawLine(renderer, 50, 5, 150, 500); … … 388 440 uiOverlay = nullptr; 389 441 } 442 443 if (fontSDLTexture != nullptr) { 444 SDL_DestroyTexture(fontSDLTexture); 445 fontSDLTexture = nullptr; 446 } 447 448 if (imageSDLTexture != nullptr) { 449 SDL_DestroyTexture(imageSDLTexture); 450 imageSDLTexture = nullptr; 451 } 452 453 TTF_CloseFont(font); 454 font = nullptr; 390 455 391 456 SDL_DestroyRenderer(renderer); -
vulkan-game.hpp
rcc4a8b5 r1f25a71 87 87 VkDescriptorImageInfo sdlOverlayImageDescriptor; 88 88 89 TTF_Font* font; 90 SDL_Texture* fontSDLTexture; 91 92 SDL_Texture* imageSDLTexture; 93 89 94 vector<VkSemaphore> imageAvailableSemaphores; 90 95 vector<VkSemaphore> renderFinishedSemaphores; -
vulkan-ref.cpp
rcc4a8b5 r1f25a71 152 152 SDL_Renderer* gRenderer = nullptr; 153 153 SDL_Texture* uiOverlay = nullptr; 154 /*** END OF REFACTORED CODE ***/155 154 156 155 TTF_Font* gFont = nullptr; … … 158 157 SDL_Texture* uiImage = nullptr; 159 158 160 /*** START OF REFACTORED CODE ***/161 159 VkInstance instance; 162 160 VkDebugUtilsMessengerEXT debugMessenger; … … 264 262 cout << "Unable to set texture blend mode! SDL Error: " << SDL_GetError() << endl; 265 263 } 266 /*** END OF REFACTORED CODE ***/ 267 268 gFont = TTF_OpenFont("fonts/lazy.ttf", 28); 264 265 gFont = TTF_OpenFont("assets/fonts/lazy.ttf", 28); 269 266 if (gFont == nullptr) { 270 267 cout << "Failed to load lazy font! SDL_ttf Error: " << TTF_GetError() << endl; … … 272 269 } 273 270 274 SDL_Color textColor = { 0, 0, 0 }; 275 276 SDL_Surface* textSurface = TTF_RenderText_Solid(gFont, "Great sucess!", textColor); 271 SDL_Surface* textSurface = TTF_RenderText_Solid(gFont, "Great success!", { 255, 255, 255 }); 277 272 if (textSurface == nullptr) { 278 273 cout << "Unable to render text surface! SDL_ttf Error: " << TTF_GetError() << endl; … … 308 303 } 309 304 310 /*** START OF REFACTORED CODE ***/311 305 void initVulkan() { 312 306 createInstance(); … … 1851 1845 SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0x00, 0x00); 1852 1846 SDL_RenderClear(gRenderer); 1853 /*** END OF REFACTORED CODE ***/1854 1847 1855 1848 SDL_Rect rect; … … 1858 1851 SDL_SetRenderDrawColor(gRenderer, 0x00, 0xFF, 0x00, 0xFF); 1859 1852 SDL_RenderFillRect(gRenderer, &rect); 1860 SDL_SetRenderDrawColor(gRenderer, 0x00, 0x9F, 0x9F, 0xFF);1861 1853 1862 1854 rect = {10, 10, 0, 0}; … … 1868 1860 SDL_RenderCopy(gRenderer, uiImage, nullptr, &rect); 1869 1861 1870 /*** START OF REFACTORED CODE ***/1871 1862 SDL_SetRenderDrawColor(gRenderer, 0x00, 0x00, 0xFF, 0xFF); 1872 1863 SDL_RenderDrawLine(gRenderer, 50, 5, 150, 500); … … 1970 1961 uiOverlay = nullptr; 1971 1962 } 1972 /*** END OF REFACTORED CODE ***/1973 1963 1974 1964 TTF_CloseFont(gFont); 1975 1965 gFont = nullptr; 1976 1966 1977 1967 if (uiText != nullptr) { … … 1985 1975 } 1986 1976 1987 /*** START OF REFACTORED CODE ***/1988 1977 SDL_DestroyRenderer(gRenderer); 1989 1978 gRenderer = nullptr;
Note:
See TracChangeset
for help on using the changeset viewer.