void dumpPNG(const std::string &filename) { #ifdef PNGOUT YImage image; image.resize(g_display_controller.getWindowWidth(), g_display_controller.getWindowHeight()); glPixelStorei(GL_PACK_ALIGNMENT, 4); glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_SKIP_ROWS, 0); glPixelStorei(GL_PACK_SKIP_PIXELS, 0); glReadBuffer(GL_BACK); glFinish(); glReadPixels(0, 0, g_display_controller.getWindowWidth(), g_display_controller.getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, image.data()); image.flip(); image.save(filename.c_str()); #endif }
// TODO: Preallocate space for for the image, use a faster method to read the buffer void dumpPNG( const std::string& filename ) { YImage image; image.resize(g_simulation_ensemble->getWindowWidth(), g_simulation_ensemble->getWindowHeight()); glPixelStorei(GL_PACK_ALIGNMENT, 4); glPixelStorei(GL_PACK_ROW_LENGTH, 0); glPixelStorei(GL_PACK_SKIP_ROWS, 0); glPixelStorei(GL_PACK_SKIP_PIXELS, 0); glReadBuffer(GL_BACK); glFinish(); glReadPixels(0, 0, g_simulation_ensemble->getWindowWidth(), g_simulation_ensemble->getWindowHeight(), GL_RGBA, GL_UNSIGNED_BYTE, image.data()); image.flip(); if( !image.save(filename.c_str()) ) { std::cerr << outputmod::startred << "TDSmoke ERROR: " << outputmod::endred << "Failed to save png image " << filename << ". Exiting." << std::endl; exit(1); } }