Changeset 1f25a71 in opengl-game for vulkan-game.cpp
- 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)
- File:
-
- 1 edited
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);
Note:
See TracChangeset
for help on using the changeset viewer.