Graphics context rendered in hardware or software?


#1

This is a fairly general question, as I am quite new to Juce. Is the normal graphics context hardware accelerated or software based? (http://learn.juce.com/doc/classGraphics.php#details)

I realize there is an OpenGLGraphics context as well, I guess the core of my question is this: 

Is there a hardware accelerated way to draw 2D graphics using convienience methods (like drawLine(), etc in the normal graphics context) AND add post processing shader effects? Or would this all need to be done in raw OpenGL? 

 


#2

If you turn on the OpenGl context, also the 2D drawing routines are done in OpenGl => huge performance gain.

So I recommend you doing that. And as far as I know there is nothing hindering you from mixing 2D and 3D. So shaders should be OK (not used them myself though).

Maybe you can describe more in detail, what you had in mind with the shader, so someone more knowledgeable can answer.

 

 


#3

By "turn on the OpenGL context" do you mean subclassing the component from the OpenGLContext class?


#4

No, I meant: In your main DocumentWindow class create a member variable for the OpgenGlContext. I.e.

class MainAppWindow   : public DocumentWindow
{
public:
    MainAppWindow();

private:

    /** OpenGL context. This is used in order to speed up 2D-drawing. I.e. also
        the GUI elements benefit from it.*/
    OpenGLContext openGLContext;    
};

The in the constructor simply attach the main window to the context:

MainAppWindow::MainAppWindow()
{
    //attach OpenGl context to main window
    openGLContext.attachTo(*this);

}

And that's it. Your application is using OpenGl rendering.


#5

Awesome, thanks!


#6

Thanks, that's exactly the answer I was looking for as far as the 2D drawing routines go. 

As for the shader question, I'd like to be able to do a post-processing effect on the whole screen. This usually involves rendering the scene to a frame buffer object rather than the screen, then running that texture through a shader, then rendering it to the screen. I'm no OpenGL expert, but I'm pretty sure this resembles how I did it last time I was doing this sort of thing. So I suppose ideally you would be able to render the 2D routines straight to an FBO. It would be great if anyone had an example of this sort of thing in Juce!


#7

You should have a look in demo applications provided with JUCE (JUCE Demo and OpenGLAppExample), you will find examples of all the stuff you need