Skip to content

Commit

Permalink
[examples] make screenshot example more interesting
Browse files Browse the repository at this point in the history
demonstrate how to save an image sequence of 12 pngs on every screenshot
  • Loading branch information
tgfrerer committed Nov 15, 2024
1 parent 0938add commit 3342f92
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ depends_on_island_module(le_log)
depends_on_island_module(le_screenshot)
depends_on_island_module(le_debug_print_text)
depends_on_island_module(le_resource_manager)
depends_on_island_module(le_swapchain_vk)
depends_on_island_module(le_png)

set (SOURCES "screenshot_example_app.cpp")
set (SOURCES ${SOURCES} "screenshot_example_app.h")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

#include "le_screenshot.h"
#include "le_debug_print_text.h"
#include "le_swapchain_vk.h"
#include "le_swapchain_img.h"
#include "le_png.h"

#include "glm/glm.hpp"
#include "glm/gtc/matrix_transform.hpp"
Expand Down Expand Up @@ -248,7 +251,7 @@ static void app_process_ui_events( app_o* self ) {
wants_toggle ^= true;
} else if ( e.key == LeUiEvent::NamedKey::eS ) {
// save screenshot
self->num_screenshot_examples_to_record = 1;
self->num_screenshot_examples_to_record = 12;
} else if ( e.key == LeUiEvent::NamedKey::eG ) {
// toggle grid
self->hide_grid ^= 1;
Expand Down Expand Up @@ -334,7 +337,16 @@ static bool screenshot_example_app_update( screenshot_example_app_o* self ) {
// in case the screen_grabber has any objects in-flight that need to be
// updated.
//
le_screenshot_api_i->le_screenshot_i.record( self->screen_grabber, rg, self->swapchain_image, &self->num_screenshot_examples_to_record, nullptr );

le_swapchain_img_settings_t settings{
.width_hint = 800, // 0 means to take the width of the renderer's first swapchain
.height_hint = 400, // 0 means to take the height of the renderer's first swapchain

.format_hint = le::Format::eR8G8B8A8Unorm,
.image_encoder_i = le_png::api->le_png_image_encoder_i,
.image_filename_template = "./capture/screenshot_%08d.png",
};
le_screenshot_api_i->le_screenshot_i.record( self->screen_grabber, rg, self->swapchain_image, &self->num_screenshot_examples_to_record, &settings );
}

if ( !self->hide_help_text ) {
Expand Down

0 comments on commit 3342f92

Please sign in to comment.