How to prevent 100 fps in openGL?

I’m wondering what the best practise is to prevent a juce::OpenGLContext from calling renderOpenGL() as fast as it can. I actually don’t do any animation, I only use openGL to do some nice 3d rendering, so in my case renderOpenGL() need only be called when a repaint() is called.
At this moment I use a juce::Thread::sleep( 40 ) in the renderOpenGL(), but than the OpenGLContext is still doing to much work.

Any help is appreciated.

Jankoen

huh? I’m pretty sure it’s limited by default to the vertical blank interrupt (?). But you can adjust it with OpenGLContext::setSwapInterval()

As far as I can see renderOpenGL() gets called as much as possible in the thread. Most of the time its about every 10-20 ms, but when nothing need to go to screen ( when window is in hidden behind another window ) its even more about: every less than 1 msec.

I my particular case I would need a redraw only when I call update, since the openGL rendering engine is only used to render a static 3D image. I would be happy if I could render a 3D drawing into an Image and plot that to screen. As soon as I post an repaint() message I would like a new renderOpenGL() call te refresh my 3D image.

Jankoen

and oh yes, It’s on OSX

Don’t know exactly how it works but you can probably used some offline buffer rendering using OpenGLFrameBuffer.
GL gurus will know better though

Have you tried setting OpenGLContext::setSwapInterval() to 1?

The whole thing about the renderOpenGL call is that it’s not tied to the normal repaint mechanism, it’s for game-like continuous rendering. At some point I’m going to figure out a way to let you write GL code inside a normal paint() method and mix it up with the 2D GL rendering, which is probably exactly what you’re looking for, but haven’t had chance to do that yet.

I tried that, it did not help. renderOpenGL() gets called at full speed regardless the setting even when I set it to 10 or os.

Indeed, what you describe is indeed exactly what I’m looking. In fact Its seems to be almost there. I tried to hack some code, but i feel a little reluctant to do that, since it would break future updates of JUCE.

but… something like this and some more editing ( disabling the OpenGL render thread ) seem to work on OSX. I have no idea how compatible this is with other platforms.

void OpenGLContext::RenderFrame( void ) { if ( CachedImage* const c = getCachedImage() ) { c->initialiseOnThread(); c->hasInitialised = true; c->renderFrame(); c->shutdownOnThread(); } };

Biggest problem is that the paint() of my openGLrender component does not get called for some reason I can’t figure out.

Another approach seems to be to use the OpenGLFrameBuffer object as suggested by otristan. But I can’t figure how to do use that but I’ll do additional investigations on that now.

Jankoen

To finish this thread:
I was not able to use OpenGLContext nor OpenGLFrameBuffer to render a single image of openGL. I completely abandoned juce for openGL at this point.

jules:
For my wishlist: a way to render openGL into an image.

Jankoen

Ok, but just in case anyone reads this thread and gets the impression that juce’s GL is broken, I should point out that you can of course render into an OpenGLFrameBuffer. The demo app does exactly that.

I don’t know what you’re doing wrong, but I do agree that it’d be cool to have a mechanism for allowing GL calls to be done inside a normal paint routine, and will be writing that soon!