Merge branch 'sdl-try-2' of github.com:Ygrik2003/VoxelEngine-Cpp into sdl-try-2

This commit is contained in:
Igor Stepanov 2025-10-10 14:56:38 +03:00
commit 640cfcc3d0
2 changed files with 14 additions and 3 deletions

View file

@ -4,6 +4,8 @@
#include <SDL3/SDL.h>
#include <SDL3/SDL_error.h>
#include <SDL3/SDL_mouse.h>
#include <SDL3/SDL_render.h>
#include <SDL3/SDL_surface.h>
#include <SDL3/SDL_timer.h>
#include <SDL3/SDL_version.h>
#include <SDL3/SDL_video.h>
@ -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<ImageData> window_sdl::takeScreenshot() {
return {};
glBindFramebuffer(GL_FRAMEBUFFER, 0);
auto data = std::make_unique<ubyte[]>(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<ImageData>(
ImageFormat::rgb888, size.x, size.y, data.release()
);
}
[[nodiscard]] bool window_sdl::isValid() const {

View file

@ -1,11 +1,10 @@
#include <SDL3/SDL_render.h>
#include <SDL3/SDL_video.h>
#include <stack>
#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<glm::vec4> scissorStack;