Hi, I’m trying to capture the screen on each frame update and I find that the first frame will always be a black picture when this is not expected.
The texture is created as such:
SharedPtr<Viewport> viewport(new Viewport(context, scene, camera);
tex = new Texture2D(context);
tex->SetSize(width, height, Graphics::GetRGBFormat(), TEXTURE_RENDERTARGET);
tex->GetRenderSurface()->SetViewport(0, viewport);
tex->GetRenderSurface()->SetUpdateMode(SURFACE_UPDATEALWAYS);
Then I’ve subscribed to the EndFrame-event in which I try to fetch the data from my texture:
int len = tex->GetDataSize(width, height);
unsigned char* buf = new unsigned char[len];
tex->GetData(0, buf);
I’ve been reading the documentation and some other topics on this forum that were slightly relevant and tried to make sure that the rendertarget is current by doing:
Graphics* graphics = GetSubsystem<Graphics>();
graphics->SetRenderTarget(0, tex);
graphics->SetViewport(IntRect(0, 0, width, height));
both in the texture-creation-block and prior to any call to GetData() without success.
I’ve also tried using glReadPixels() but if I use my rendertarget-texture all I get is junk.
If I try just using a Urho3D::Renderer instead of the texture I do indeed get what should be visible on my screen.
However, the images are rotated 180 degrees and are mirrored.
I greatly appreciate any input. What am I missing here?