feat(renderer): add screenshot capture with F2

This commit is contained in:
2026-08-07 10:59:43 +08:00
parent 1c2c77f83f
commit 607be871b1
4 changed files with 63 additions and 4 deletions

View File

@@ -25,7 +25,7 @@ class DevPanel;
class Renderer {
public:
constexpr static int NUM_VAO = 7;
constexpr static const char* SCREENSHOT_PATH = "./screenshot";
Renderer(TextureManager& texture_manager, Config& config);
~Renderer();
void reload_config();
@@ -83,6 +83,8 @@ public:
ModelRender& model_renderer();
void save_screenshot();
private:
TextureManager& m_texture_manager;
bool m_init = false;
@@ -98,6 +100,8 @@ private:
float m_window_width = 0.0f;
float m_window_height = 0.0f;
bool m_save_screenshot = false;
glm::mat4 m_world_proj_matrix;
std::unique_ptr<VertexBuffer> m_sky_vbo;
@@ -129,6 +133,7 @@ private:
void updata_framebuffer(int width, int height);
void init_quad();
void init_text();
void handle_screenshot();
};
} // namespace Cubed

View File

@@ -1,11 +1,23 @@
#pragma once
#include <SDL3/SDL_timer.h>
#include <chrono>
#include <cstdint>
#include <format>
#include <string>
namespace Cubed {
namespace Tools {
// return ms
inline uint64_t get_time_ticks() { return SDL_GetTicks(); }
inline std::string get_time_date_str() {
static auto* zone = std::chrono::current_zone();
auto now = std::chrono::system_clock::now();
auto local =
std::chrono::time_point_cast<std::chrono::seconds>(zone->to_local(now));
return std::format("{:%F %T}", local);
}
} // namespace Tools
} // namespace Cubed