OpenGL LowLevelGraphicsContext for general Component drawing


I wonder if it is possible to use, instead of the default 2D renderer, an OpenGL LowLevelGraphicsContext for all (Component) drawing operations in Juce? The feature list states: "State of the art, sub-pixel accurate 2D rendering engine with support for affine transformations and high DPI displays. The engine supports various backends for accelerated rendering such as CoreGraphics and OpenGL."

So I suppose it is possible? There is createOpenGLGraphicsContext() in juce_OpenGLGraphicsContext.h. How would I pass that context (or any specialized graphics context for that matter) to my component/toplevelwindow s.t. the draw routines are called using that one instead of the default one?

I've seen this thread which suggests that it's not yet possible with the GL context, however it's a bit old:

How's the state of affairs?

Thanks in advance!

Yes, of course - that's been possible for years! The big demo app lets you switch between rendering engines by pressing the 1, 2 or 3 keys when it's running.

Great, will look into the code then, thanks! Somehow I didn't manage to look it up in the API docs myself, had looked at Compnent, Graphics, LowLevelGraphicsContext, DocumentWindow and the respective base classes... Just now I'm wading through the examples, will post if I found it, for anyone else reading this.

Ok the relevant code is in examples/Demo/Source/MainWindow.cpp:616.

If the OpenGL renderer is used, the OpenGLContext needs first be attached to the toplevel component of a Component hierarchy. The actual switch is performed using ComponentPeer::setCurrentRenderingEngine(int index). I see that the index parameter is not further documented, and in the Demo you use the "OpenGL Renderer" name to identify the GL renderer. In order not to have to search for which of the renderers is the OpenGL renderer in client code, what do you think of providing an enum with the respective engines which can be used as index?

Now let me have a closer look at what the ComponentPeer class is used for, didn't notice this until now, and failed to search for that one earlier.

Thanks for you support!