Does a screenshot and tells the bitmap lib to save out the picture as a tga
| 1271 | |
| 1272 | // Does a screenshot and tells the bitmap lib to save out the picture as a tga |
| 1273 | void DoScreenshot() { |
| 1274 | int count; |
| 1275 | char str[255], filename[255]; |
| 1276 | CFILE *infile; |
| 1277 | int done = 0; |
| 1278 | int width = 640, height = 480; |
| 1279 | |
| 1280 | if (UseHardware) { |
| 1281 | rendering_state rs; |
| 1282 | rend_GetRenderState(&rs); |
| 1283 | width = rs.screen_width; |
| 1284 | height = rs.screen_height; |
| 1285 | } |
| 1286 | |
| 1287 | StopTime(); |
| 1288 | |
| 1289 | // Tell our renderer lib to take a screen shot |
| 1290 | auto screenshot = rend_Screenshot(); |
| 1291 | |
| 1292 | if (!screenshot || screenshot->getData() == nullptr) { |
| 1293 | AddHUDMessage(TXT_ERRSCRNSHT); |
| 1294 | return; |
| 1295 | } |
| 1296 | |
| 1297 | // Find a valid filename |
| 1298 | count = 1; |
| 1299 | while (!done) { |
| 1300 | snprintf(str, sizeof(str), "Screenshot%.3d.png", count); |
| 1301 | ddio_MakePath(filename, Base_directory, str, NULL); |
| 1302 | infile = (CFILE *)cfopen(filename, "rb"); |
| 1303 | if (infile == NULL) { |
| 1304 | done = 1; |
| 1305 | continue; |
| 1306 | } else |
| 1307 | cfclose(infile); |
| 1308 | |
| 1309 | count++; |
| 1310 | if (count > 999) |
| 1311 | break; |
| 1312 | } |
| 1313 | |
| 1314 | // Now save it |
| 1315 | screenshot->saveAsPNG(filename); |
| 1316 | |
| 1317 | if (Demo_flags != DF_PLAYBACK) { |
| 1318 | AddHUDMessage(TXT_SCRNSHT, filename); |
| 1319 | } |
| 1320 | |
| 1321 | StartTime(); |
| 1322 | } |
no test coverage detected