| 216 | |
| 217 | |
| 218 | void ScreenShot::_singleCapture( GuiCanvas *canvas ) |
| 219 | { |
| 220 | // Let the canvas render the scene. |
| 221 | canvas->renderFrame( false ); |
| 222 | |
| 223 | // Now grab the current back buffer. |
| 224 | GBitmap *bitmap = _captureBackBuffer(); |
| 225 | |
| 226 | // The current GFX device couldn't capture the backbuffer or it's unable of doing so. |
| 227 | if (bitmap == NULL) |
| 228 | return; |
| 229 | |
| 230 | // We captured... clear the flag. |
| 231 | mPending = false; |
| 232 | |
| 233 | // We gotta attach the extension ourselves. |
| 234 | char filename[256]; |
| 235 | dSprintf( filename, 256, "%s.%s", mFilename, mWriteJPG ? "jpg" : "png" ); |
| 236 | |
| 237 | // Open up the file on disk. |
| 238 | FileStream fs; |
| 239 | if ( !fs.open( filename, Torque::FS::File::Write ) ) |
| 240 | Con::errorf( "ScreenShot::_singleCapture() - Failed to open output file '%s'!", filename ); |
| 241 | else |
| 242 | { |
| 243 | // Write it and close. |
| 244 | if ( mWriteJPG ) |
| 245 | bitmap->writeBitmap( "jpg", fs ); |
| 246 | else |
| 247 | bitmap->writeBitmap( "png", fs ); |
| 248 | |
| 249 | fs.close(); |
| 250 | } |
| 251 | |
| 252 | // Cleanup. |
| 253 | delete bitmap; |
| 254 | } |
| 255 | |
| 256 | |
| 257 | DefineEngineFunction( screenShot, void, |
nothing calls this directly
no test coverage detected