Amerio.Stephane Posted June 22, 2023 Posted June 22, 2023 Hi, I'm trying to do a screenshot without the GUI visible and in high res. Using "screenshot" command would capture the GUI, and will also use the current image size. I'm using this code at the moment to capture the current view and save it in the user's Picture folder: #include <chrono> // chrono::system_clock #include <ctime> // localtime #include <sstream> // stringstream #include <iomanip> // put_time #include <string> // string #include <iostream> #include <windows.h> #include <shlobj.h> std::string GetImagesFolderPath() { PWSTR path; HRESULT result = SHGetKnownFolderPath(FOLDERID_Pictures, 0, NULL, &path); if (SUCCEEDED(result)) { std::wstring wstr(path); CoTaskMemFree(path); std::string str(wstr.begin(), wstr.end()); return str; } else return ""; } void AppSystemLogic::cmd_printscreen(int argc, char** argv) { auto now = std::chrono::system_clock::now(); auto in_time_t = std::chrono::system_clock::to_time_t(now); std::stringstream ss; ss << GetImagesFolderPath() << "\\" << std::put_time(std::localtime(&in_time_t), "capture_%Y%m%d_%H%M%S.png"); const int viewportHeight = 1080; const int viewportWidth = 1920; ViewportPtr viewport = Viewport::create(); viewport->setSkipFlags(Viewport::SKIP_VELOCITY_BUFFER | Viewport::SKIP_VISUALIZER); viewport->setRenderMode(Viewport::RENDER_DEPTH_GBUFFER_FINAL); viewport->setNodeLightUsage(Viewport::USAGE_WORLD_LIGHT); TexturePtr texture = Texture::create(); texture->create2D(viewportWidth, viewportHeight, Unigine::Texture::FORMAT_RGB8, // RGB only otherwise the saved PNG will use the alpha (sky is masked out) Texture::SAMPLER_FILTER_LINEAR | Texture::SAMPLER_ANISOTROPY_16 | Texture::FORMAT_USAGE_RENDER); { const int streaming_mode = Render::getStreamingMode(); Render::setStreamingMode(Render::STREAMING_FORCE); // force load texture const float e = Render::getExposureAdaptation(); Render::setExposureAdaptation(0); viewport->renderTexture2D(Game::getPlayer()->getCamera(), texture); Render::setExposureAdaptation(e); Render::setStreamingMode(streaming_mode); // restore streaming mode } ImagePtr image = Image::create(); texture->getImage(image); const char* filename = ss.str().c_str(); image->save(filename); // JPG doesn't work. Why? Log::message("Screenshot saved to %s\n", filename); } But the saved image is very noisy, especially all gradients and shadows. Is there anything I could do? With my code: with screenshot command:
silent Posted June 23, 2023 Posted June 23, 2023 Hi Stephane, If you are creating new viewport you need to wait 16-30 frames until the temporal post-processing effects will be rendered correctly. How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN
Recommended Posts