Using a GL Context without attaching a Component

Hi Admins, hi Community,

I just wonder if there is any possibility of using a GL Context (with their associated rendering object in a back thread) but without attaching a Component class?

The reason is using framebuffer objects bound to this GL context to rendering images and copying it to a video card buffer without the need to present it to screen.

AFAIK, a GLContext object will not properly configured until a Component object is attached to and even it has to be visible.

Thank you in advance,

Gabriel Solsona

This is currently not possible and is also quite hard to do with many native APIs as well. The reason is that the OS needs to know which pixel format and GPU to use - which it can only know when it knows on which monitor the context will be rendered.

As workaround, you can create a component, add it to the desktop with addToDesktop, but move it literally “offscreen”, i.e. move it so it can never be visible. For example, this code works:

class OpenGLComponent : public Component, private OpenGLRenderer
        context.setRenderer (this);
        context.attachTo (*this);
        setSize (600, 400);
        context.setRenderer (nullptr);
    void newOpenGLContextCreated() override
        DBG ("newOpenGLContextCreated");
    void renderOpenGL() override
        OpenGLHelpers::clear (Colours::lightblue);
    void openGLContextClosing() override
        DBG ("newOpenGLContextClosing");

    OpenGLContext context;
void createOpenGLContext()
    ScopedPointer<OpenGLComponent> fakeOpenGLComponent = OpenGLComponent;
    fakeOpenGLComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks | ComponentPeer::windowIgnoresKeyPresses);
    fakeOpenGLComponent->setTopLeftPosition (-700, -500);
    fakeOpenGLComponent->setVisible (true);

Fabian, thank you for your answer, this is just want I was looking for.

Just to confirm, the render output can be sent to a instantiated framebuffer and also a shader object can be added to this pipeline, isn’t it?


Yes absolutely!

Great news!!!