From 5906421dcf3c49664f9f54b89be95cd8817b8845 Mon Sep 17 00:00:00 2001 From: Stepanov Igor Date: Tue, 7 Oct 2025 23:28:17 +0300 Subject: [PATCH] restore screenshot logic --- src/window/detail/window_sdl.cpp | 13 ++++++++++++- src/window/detail/window_sdl.hpp | 4 ++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/window/detail/window_sdl.cpp b/src/window/detail/window_sdl.cpp index 5b43cfcad..b8a4054d0 100644 --- a/src/window/detail/window_sdl.cpp +++ b/src/window/detail/window_sdl.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include #include #include @@ -212,6 +214,8 @@ window_sdl::window_sdl(DisplaySettings *settings, std::string title) noexcept { return; } + renderer = SDL_CreateRenderer(window, "vc_main"); + float scale = SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay()); logger.info() << "monitor content scale: " << scale; @@ -420,8 +424,15 @@ void window_sdl::setFramerate(int framerate) { } // todo: move somewhere +// Possible do with SDL_RenderReadPixels std::unique_ptr window_sdl::takeScreenshot() { - return {}; + glBindFramebuffer(GL_FRAMEBUFFER, 0); + auto data = std::make_unique(size.x * size.y * 3); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glReadPixels(0, 0, size.x, size.y, GL_RGB, GL_UNSIGNED_BYTE, data.get()); + return std::make_unique( + ImageFormat::rgb888, size.x, size.y, data.release() + ); } [[nodiscard]] bool window_sdl::isValid() const { diff --git a/src/window/detail/window_sdl.hpp b/src/window/detail/window_sdl.hpp index 845366f1c..e26fc6768 100644 --- a/src/window/detail/window_sdl.hpp +++ b/src/window/detail/window_sdl.hpp @@ -1,11 +1,10 @@ +#include #include #include #include "window/window.hpp" -struct SDL_Window; - class window_sdl final : public Window { public: window_sdl(DisplaySettings *settings, std::string title) noexcept; @@ -49,6 +48,7 @@ private: bool fullscreen = false; SDL_Window *window = nullptr; + SDL_Renderer *renderer = nullptr; SDL_GLContext context = nullptr; std::stack scissorStack;