Changeset 6bfd91c in opengl-game for vulkan-game.cpp
- Timestamp:
- Jun 10, 2020, 9:47:29 PM (4 years ago)
- Branches:
- feature/imgui-sdl, master
- Children:
- aa7707d
- Parents:
- f809ae6
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
rf809ae6 r6bfd91c 21 21 this->gui = nullptr; 22 22 this->window = nullptr; 23 this->font = nullptr;24 this->fontSDLTexture = nullptr;25 this->imageSDLTexture = nullptr;26 23 27 24 this->currentFrame = 0; … … 146 143 // TODO: Print the filename of the font in the error message 147 144 148 font = TTF_OpenFont("assets/fonts/lazy.ttf", 28);149 if ( font == nullptr) {145 lazyFont = TTF_OpenFont("assets/fonts/lazy.ttf", 28); 146 if (lazyFont == nullptr) { 150 147 cout << "Failed to load lazy font! SDL_ttf Error: " << TTF_GetError() << endl; 151 148 return RTWO_ERROR; 152 149 } 153 154 SDL_Surface* fontSDLSurface = TTF_RenderText_Solid(font, "Great success!", { 255, 255, 255 });155 if (fontSDLSurface == nullptr) {156 cout << "Unable to render text surface! SDL_ttf Error: " << TTF_GetError() << endl;157 return RTWO_ERROR;158 }159 160 fontSDLTexture = SDL_CreateTextureFromSurface(renderer, fontSDLSurface);161 if (fontSDLTexture == nullptr) {162 cout << "Unable to create texture from rendered text! SDL Error: " << SDL_GetError() << endl;163 SDL_FreeSurface(fontSDLSurface);164 return RTWO_ERROR;165 }166 167 SDL_FreeSurface(fontSDLSurface);168 169 // TODO: Load a PNG instead170 SDL_Surface* imageSDLSurface = SDL_LoadBMP("assets/images/spaceship.bmp");171 if (imageSDLSurface == nullptr) {172 cout << "Unable to load image " << "spaceship.bmp" << "! SDL Error: " << SDL_GetError() << endl;173 return RTWO_ERROR;174 }175 176 imageSDLTexture = SDL_CreateTextureFromSurface(renderer, imageSDLSurface);177 if (imageSDLTexture == nullptr) {178 cout << "Unable to create texture from BMP surface! SDL Error: " << SDL_GetError() << endl;179 SDL_FreeSurface(imageSDLSurface);180 return RTWO_ERROR;181 }182 183 SDL_FreeSurface(imageSDLSurface);184 150 185 151 proggyFont = TTF_OpenFont("assets/fonts/ProggyClean.ttf", 16); … … 1142 1108 delete screens[SCREEN_GAME]; 1143 1109 1144 // TODO: Check if any of these functions accept null parameters 1145 // If they do, I don't need to check for that 1146 1147 if (fontSDLTexture != nullptr) { 1148 SDL_DestroyTexture(fontSDLTexture); 1149 fontSDLTexture = nullptr; 1150 } 1151 1152 if (imageSDLTexture != nullptr) { 1153 SDL_DestroyTexture(imageSDLTexture); 1154 imageSDLTexture = nullptr; 1155 } 1156 1157 TTF_CloseFont(font); 1158 font = nullptr; 1110 if (lazyFont != nullptr) { 1111 TTF_CloseFont(lazyFont); 1112 lazyFont = nullptr; 1113 } 1159 1114 1160 1115 if (proggyFont != nullptr) {
Note:
See TracChangeset
for help on using the changeset viewer.