Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions botcraft/include/botcraft/Renderer/RenderingManager.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace Botcraft

// Take a screenshot of the current frame and save it to path
void Screenshot(const std::string& path);
void Screenshot(std::function<void(const int, const int, const std::vector<unsigned char> &, void *arg)> callback, void *arg);

void SetCurrentBehaviourTree(const BaseNode* root) const;
void ResetBehaviourState() const;
Expand Down Expand Up @@ -182,8 +183,10 @@ namespace Botcraft
std::function<void(double, double)> MouseCallback;
std::function<void(std::array<bool, static_cast<int>(KEY_CODE::NUMBER_OF_KEYS)>, double)> KeyboardCallback;

std::string screenshot_path;
bool take_screenshot;
std::string screenshot_path;
std::optional<std::function<void(const int, const int, const std::vector<unsigned char> &, void *arg)>> screenshot_callback;
void *screenshot_arg { nullptr };
bool take_screenshot;

bool running;

Expand Down
15 changes: 14 additions & 1 deletion botcraft/src/Renderer/RenderingManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,10 @@ namespace Botcraft
std::vector<unsigned char> pixels(current_window_height * current_window_width * 3);
glReadPixels(0, 0, current_window_width, current_window_height, GL_RGB, GL_UNSIGNED_BYTE, pixels.data());

WriteImage(screenshot_path, current_window_height, current_window_width, 3, pixels.data(), true);
if (screenshot_path.empty() == false)
WriteImage(screenshot_path, current_window_height, current_window_width, 3, pixels.data(), true);
else
screenshot_callback.value()(current_window_width, current_window_height, pixels, screenshot_arg);
take_screenshot = false;
}

Expand Down Expand Up @@ -385,6 +388,16 @@ namespace Botcraft
void RenderingManager::Screenshot(const std::string& path)
{
screenshot_path = path;
screenshot_callback.reset();
screenshot_arg = nullptr;
take_screenshot = true;
}

void RenderingManager::Screenshot(std::function<void(const int, const int, const std::vector<unsigned char> &, void *args)> callback, void *arg)
{
screenshot_path.clear();
screenshot_callback = callback;
screenshot_arg = arg;
take_screenshot = true;
}

Expand Down