Is this possible without tricking by ImageRenders ?
The only way would be to render your opengl off-screen, then get it into a juce image, which you can draw into your component. Not great in terms of performance, but it avoids all the heavyweight windowing problems.
not sure what you mean… Rendering it offscreen wouldn’t limit the things you could use it for (?)
Nevermind… I’ll try it. Would you have seen a code sample for this in Juce Forum ?
I’ve never seen one, but Component’s snapshot method should be all you need.
I’ve tried it, but I get a black rendering : size is okay, display : ok, but full-black ?
Would you know why ?
Iv’e put it in my Mycomp::MyComp() :
testGL = new MyOpenGLComponent();
image = new Image (Image::RGB, testGL->getHeight(), testGL->getWidth(), true);
Graphics g (*image);
I’ve put it in MyComp::paint() :
const Rectangle areaToGrab(0,0,testGL->getWidth(),testGL->getHeight());
Image* im = testGL->createComponentSnapshot(areaToGrab,false);
g.drawImage (im, 0, 0, im->getWidth(), im->getHeight(), 0, 0, image->getWidth(), image->getHeight());
And I get :
It won’t work with createComponentSnapshot(), opengl windows are “painted” by the driver, so you won’t get back the image like this.
To get the image from GPU to RAM, you need to ask the driver, using either glReadPixels(), or using Frame Buffer Objects (render to texture).
Anyway doing this is highly inefficient, 3d acceleration is done for cpu -> gpu efficiency, not the other way.
What is your main purpose, why would you need opengl ?
thomas : I agree all your notes.
In fact I dont need specifically 3D support, I work only in 2D, but I ve started to use openGl for better paint performance, and maybe cutter graphic dynamics and results.
But since what you say, it’s not the good choice.
I’m just starting a Reaktor-like or MaxMsP-like component, with thus boxes and wires linking boxes, and of course paths to catch and move all these elements.
It is what I decided to use openGl for.
it’s a bit old and dirty code (and it generated me some headaches with specific drivers) but should be what you are looking for (reimplementation of the openGLComponent::createSnapshot or whatever.
Don’t know if Jules ever imported into the OpenGLComponent class:
hope it helps as starting point for your tests. don’t forget to post here your results, maybe could come into hand for someone else !
[quote=“thomas”]It won’t work with createComponentSnapshot(), opengl windows are “painted” by the driver, so you won’t get back the image like this.
True that. I forgot that GL is video card context.
[quote]GL is video card context.[/quote]Yes, what causes the same result than when you make a Windows snapshot : video card stuff is blackened.
thanks kraken, i’m gonna test that, the fact is that this openGL component will be my very main one, i’m trying to implement such a soft like MaxMSP where the main task window seems to ben openGL-ed.
NB : i(m working on Mac OS X Leopard (10.5.5)
AFAIK MaxMSP 5 is written using Juce and maybe Cairo here and there
there’s OpenGL but only in jitter separate windows.
trying to embed an OpenGL context inside a Viewport is going to give you lots of headaches.
if you want to wire some devices together have a look at the juce plugin host code.
Using OpenGL just for 2D because it could be faster doesn’t sound like a good approach. Juce already has enough 2D primitives and if you’ve not enough you can still use AGG or Cairo.
Only if you need 3D rendering and a good framerate then OpenGL is a good candidate.
[quote]Only if you need 3D rendering and a good framerate then OpenGL is a good candidate.[/quote]Definetely true.
Which elements from MaxMSP 5 let you think it uses Cairo ?
But at any case, the fact is that I need a vectorial painter,
cause I’ll make viewer as the exploring one in MaxMSP 5 : when you have a mini from your board and specify a view rectangle inside.
With an OpenGL comp, this is the typical thing which seemed easy to do with openGl stuff.
Only if you need 3D rendering and a good framerate then OpenGL is a good candidate.[/quote]Since which value do you consider to gat a high framerate ?