I'm trying to generate images for thumbnails and minimaps.
I have 2 different questions:
1. Can we render a scene to texture and save to image file using headless mode? From what I found, it seems it's not possible.
2. I rendered my scene using the sample code (in sample.inl)
// Take screenshot
else if (key == '9')
Graphics* graphics = GetSubsystem<Graphics>();
// Here we save in the Data folder with date and time appended
screenshot.SavePNG(GetSubsystem<FileSystem>()->GetProgramDir() + "Data/Screenshot_" +
Time::GetTimeStamp().Replaced(':', '_').Replaced('.', '_').Replaced(' ', '_') + ".png");
This code is working just fine. But I have to wait until the scene is rendered and I don't know when the scene will be rendered. I have to wait for few update loops before it actually drawing the scene.
So I tried calling Renderer's Update and Render function and then take the screenshot.
This is working but it gives me weird result.
(I'll post the expected image later because I cannot post 2 images)
It seems to me the there's a problem with the depth test.
Any idea what's wrong?
This is my code:
SharedPtr<Viewport> viewport(new Viewport(context_, scene_, cameraNode_->GetComponent<Camera>()));
m_textureOut = new Texture2D(context_);
m_textureOut->SetSize(width, height, Graphics::GetRGBFormat(), TEXTURE_RENDERTARGET);
RenderSurface* renderSurface = m_textureOut->GetRenderSurface();
unsigned char* _ImageData = new unsigned char[m_textureOut->GetDataSize(width, height)];
Image* pImage = new Image(context_);
pImage->SetSize(width, height, 3);