Jump to content

[SOLVED] Unigine 2.16 Extern Window's screenshot is not working.


photo

Recommended Posts

Hello.

I'm rendering the window creation to use based on an already created window handle.

SystemProxyKOVI::SystemProxyKOVI() : CustomSystemProxy(SYSTEM_PROXY_MOUSE | SYSTEM_PROXY_KEYBOARD)

...

                engine_window->setNestedUsage(true);
                engine_window->setGroupUsage(false);
                engine_window->setMain(true);
                engine_window->setConsoleUsage(true);
                engine_window->setFocus();
 

but below function is not working. Note that no error messages are output in the log.

 Unigine::Console::run("screenshot");

It is also possible to refer to the screenshot sample provided, but it is difficult to refer to because the screen to capture is a panorama.

When using an external window, I thought that the screenshot function did not work due to insufficient settings, so I tried various methods, but failed.
Please explain how to approach it.
thank you

Edited by KOVIAHN
Link to comment

Hello.

Screenshots are currently only available for EngineWindow. But you can add similar logic for external windows. I did this using the example of the previous CustomWinAPIProxy.

Add screenshot logic to ExternalWindow:

class ExternalWindow
{
public:
	// ...
	virtual void doRender()
	{
		// ...
		// custom render
		// ...

		if (screenshots.size())
		{
			screenshot_texture = Render::getTemporaryTexture2D(size.x, size.y, Texture::FORMAT_RGBA8);
			screenshot_texture->copy2D();
		}
	}

	virtual void doSwap()
	{
		if (screenshots.size() && screenshot_texture)
		{
			ImagePtr screenshot_image = Image::create();
			screenshot_texture->getImage(screenshot_image);
			if (Render::getAPI() == Render::API_OPENGL)
				screenshot_image->flipY();

			for (const auto &path : screenshots)
				screenshot_image->save(path);
			screenshots.clear();

			screenshot_texture = nullptr;
		}
	}

	void takeScreenshot(const char *path) { screenshots.append(path); }
	// ...

private:
	Math::ivec2 size{1600, 900};
	ViewportPtr viewport;

	Vector<String> screenshots;
	TexturePtr screenshot_texture;
};

Also add the necessary functions to the proxy:

class CustomWinAPIProxy : public Unigine::CustomSystemProxy
{
	// ...
public:
	void takeScreenshots();

private:
	void take_screenshots(int, char **);
	// ...
};
#include <UnigineDir.h>
#include <UnigineCallback.h>
  
// ...
void CustomWinAPIProxy::mainUpdate()
{
	static bool add_command = true;
	if (add_command)
	{
		Console::addCommand("screenshot_external", "screenshot_external", MakeCallback(this, &CustomWinAPIProxy::take_screenshots));
		add_command = false;
	}
}
// ...
void CustomWinAPIProxy::takeScreenshots()
{
	if (external_windows_.empty())
		return;

	String path(Engine::get()->getSavePath());
	path += "screenshots/";

	Dir::mkdir(path);

	String extension = Console::getString("screenshot_extension");

	static int counter = 0;
	for (auto window : external_windows_)
	{
		window->takeScreenshot(path + String::format("%d.", counter) + extension);
		counter++;
	}
}

void CustomWinAPIProxy::take_screenshots(int, char **)
{
	takeScreenshots();
}
// ...

You can now take screenshots using the method takeScreenshots() or using the console command "screenshot_external".

  • Like 3
Link to comment
  • silent changed the title to [SOLVED] Unigine 2.16 Extern Window's screenshot is not working.
×
×
  • Create New...