It was my fault, the 3D engine I use (Chai3D) has a flag where I have to tell the engine when I’d like to render into an already bound FrameBuffer. Now it works almost fine.
Maybe I did something wrong, but there is an issue with transparency and aliasing. I’ve attached three PNGs. One is a screenshot, the other is the captured frame, and the third is the same captured frame, but with a grid layer added under it in PS.
I think it’s something with the Image’s underlying Context / PixelFormat / FrameBuffer, but I can’t access them. The context for the renderer looks like this:
OpenGLPixelFormat format;
format.multisamplingLevel = 8;
format.depthBufferBits = 16;
context.setComponentPaintingEnabled(true);
context.setMultisamplingEnabled(true);
context.setPixelFormat(format);
context.setSwapInterval(0);
context.setRenderer(this);
context.attachTo(*this);
context.setContinuousRepainting(false);
And this is the code I used. I removed all not-frame-capture-related code, rendering directly to the context above works just fine (screenshot.png).
void Renderer::newOpenGLContextCreated ()
{
jassert(OpenGLHelpers::isContextActive());
frameImage = Image(Image::PixelFormat::ARGB, getWidth(), getHeight(), true, OpenGLImageType());
frameBuffer = OpenGLImageType::getFrameBufferFrom(frameImage);
}
void Renderer::renderOpenGL ()
{
if (wasResized) // Is this necessary?
{
frameImage = Image(Image::PixelFormat::ARGB, getWidth(), getHeight(), true, OpenGLImageType());
frameBuffer = OpenGLImageType::getFrameBufferFrom(frameImage);
wasResized = false;
}
worldLock.acquire();
frameBuffer->makeCurrentAndClear();
camera->renderView(getWidth(), getHeight(), 0, C_STEREO_LEFT_EYE, false);
frameBuffer->releaseAsRenderingTarget();
File temp("/Users/MyUser/Desktop/image.png");
if (temp.existsAsFile())
{
temp.deleteFile();
}
FileOutputStream stream(temp);
PNGImageFormat format;
format.writeImageToStream(frameImage, stream);
worldLock.release();
}
What should I do to achieve the same result as screenshot.png? And another important question, how can I do itt offscreen? As I experienced, renderOpenGL() called only when the renderer is added to the display list.