Skip to content

Commit

Permalink
Added experimental headless screen capture
Browse files Browse the repository at this point in the history
  • Loading branch information
Rabbidon committed Dec 3, 2022
1 parent a9e93a7 commit dce23d8
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 2 deletions.
7 changes: 7 additions & 0 deletions minetest.conf
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
name = me
update_last_checked = 1670077920
menu_last_game = minetest
selected_world_path = /home/edwin/minetest/bin/../worlds/new
server_announce = false
enable_damage = true
creative_mode = false
mainmenu_last_selected_world = 1
21 changes: 21 additions & 0 deletions src/client/render/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ void RenderingCore::initialize()
createPipeline();
}

void RenderingCore::savetex(video::ITexture *texture, std::string filename, video::IVideoDriver* videoDriver) {
video::IImage* image = videoDriver->createImageFromData(
texture->getColorFormat(),
texture->getSize(),
texture->lock(irr::video::E_TEXTURE_LOCK_MODE::ETLM_READ_WRITE),
true //copy mem
);
videoDriver->writeImageToFile(image, "temp.png");
texture->unlock();
}

void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
bool _draw_wield_tool, bool _draw_crosshair)
{
Expand All @@ -56,8 +67,18 @@ void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_min
context.show_hud = _show_hud;
context.show_minimap = _show_minimap;

TextureBuffer *buffer = pipeline->createOwned<TextureBuffer>();
buffer->setTexture(0, v2f(1.0f, 1.0f), "idk_lol", video::ECF_A8R8G8B8);
auto tex = new TextureBufferOutput(buffer, 0);
pipeline->setRenderTarget(tex);

for (auto &step: pipeline->m_pipeline)
step->setRenderTarget(tex);

pipeline->reset(context);
pipeline->run(context);

savetex(tex->buffer->getTexture(0),"mu",device->getVideoDriver());
}

v2u32 RenderingCore::getVirtualSize() const
Expand Down
3 changes: 3 additions & 0 deletions src/client/render/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class RenderingCore
RenderingCore &operator=(const RenderingCore &) = delete;
RenderingCore &operator=(RenderingCore &&) = delete;


void savetex(video::ITexture *texture, std::string filename, video::IVideoDriver* videoDriver);

void initialize();
void draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
bool _draw_wield_tool, bool _draw_crosshair);
Expand Down
6 changes: 4 additions & 2 deletions src/client/render/pipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ class TextureBufferOutput : public RenderTarget
TextureBufferOutput(TextureBuffer *buffer, const std::vector<u8> &texture_map, u8 depth_stencil);
virtual ~TextureBufferOutput() override;
void activate(PipelineContext &context) override;
TextureBuffer *buffer;

private:
static const u8 NO_DEPTH_TEXTURE = 255;

TextureBuffer *buffer;
std::vector<u8> texture_map;
u8 depth_stencil { NO_DEPTH_TEXTURE };
video::IRenderTarget* render_target { nullptr };
Expand Down Expand Up @@ -406,8 +407,9 @@ class RenderPipeline : public RenderStep

virtual void setRenderSource(RenderSource *source) override;
virtual void setRenderTarget(RenderTarget *target) override;
private:
std::vector<RenderStep *> m_pipeline;
private:

std::vector< std::unique_ptr<RenderPipelineObject> > m_objects;
DynamicSource m_input;
DynamicTarget m_output;
Expand Down
Binary file added temp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dce23d8

Please sign in to comment.