Juce component into an OpenGL texture

Not sure if this has been covered - I couldn’t find it, but what’s the best way to get a Juce component as a complete image to use as a texture (with an alpha channel?

Ideally, I would like a callback, like a listener call, when the juce component (a window) or any of it’s children have drawn, so I can move it to a texture.

I guess I can’t do anything on a thread really, seeing as it’s drawing?

And is there a ‘fast path’ so I’m not wasting time doing actual screen drawing that will never be seen? If I don’t make the component visible, will it still draw? Or just when I ask it to? Seems like I’ll have to hook into the renderer somehow maybe?


to get the snapshot, can’t you just cheat and use:





As for the callback, posting an async message at the end of the paint() method is probably safe, I’d imagine.

Well, yes, but since the entire juce UI will be expressed via the image, I’d like to make sure I’m not drawing too many times, and that I do all the updates needed and no more.

So, I’d rather know if there’s a non-cheat method :slight_smile:


It’s not that simple - comps are only drawn when a ComponentPeer needs something to put on-screen, and the repainting lives deep inside the platform-specific code. If they’re offscreen, there’s no repaint mechanism involved at all.

The “correct” way to do it would be to write a componentpeer that draws itself to a texture, and that would handle all interaction with the component. Quite a tricky job, though…

Well, then what happens when we send a repaint()? That goes all the way up to the OS and then it comes back and triggers the actual drawing? Hmm.

OK, strangely enough, I may be up fro trying to sub-class or copy HIViewComponentPeer. A fair amount should be the same.

So - assuming I can translate most stuff, how do I trick juce into using my component peer not it’s own?


Looks like either overriding addtoDesktop, or changing the OS getComponentPeer to use styleflags somehow.

Maybe I just make my own addToOpenGLScreen()

I get the feeling there’ll be some gotchas too - can’t see how it would work for anyone else.


There will be some gotchas. Take a look at the MagnifierComponent for tips - that uses a fake ComponentPeer.