void paintComponent()
    {
        // you mustn't set your own cached image object when attaching a GL context!
        jassert (get (component) == this);

        updateViewportSize (false);

        if (! ensureFrameBufferSize())
            return;

        RectangleList invalid (viewportArea);
        invalid.subtract (validArea);
        validArea = viewportArea;

        if (! invalid.isEmpty())
        {
            clearRegionInFrameBuffer (invalid, (float) scale);

            {
                ScopedPointer<LowLevelGraphicsContext> g (createOpenGLGraphicsContext (context, cachedImageFrameBuffer));
                g->addTransform (AffineTransform::scale ((float) scale));
                g->clipToRectangleList (invalid);

                paintOwner (*g);
                JUCE_CHECK_OPENGL_ERROR
            }

            if (! context.isActive())
                context.makeActive();
        }
Пример #2
0
    void drawBackground2DStuff()
    {
        // Create an OpenGLGraphicsContext that will draw into this GL window..
        ScopedPointer<LowLevelGraphicsContext> glRenderer (createOpenGLGraphicsContext (openGLContext,
                                                                                        getContextWidth(),
                                                                                        getContextHeight()));

        if (glRenderer != nullptr)
        {
            Graphics g (glRenderer);
            g.addTransform (AffineTransform::scale ((float) getScale()));

            // This stuff just creates a spinning star shape and fills it..
            Path p;
            const float scale = getHeight() * 0.4f;
            p.addStar (Point<float> (getWidth() * 0.7f, getHeight() * 0.4f), 7,
                       scale * (float) sizeSlider.getValue(), scale,
                       rotation / 50.0f);

            g.setGradientFill (ColourGradient (Colours::green.withRotatedHue (fabsf (::sinf (rotation / 300.0f))),
                                               0, 0,
                                               Colours::green.withRotatedHue (fabsf (::cosf (rotation / -431.0f))),
                                               0, (float) getHeight(), false));
            g.fillPath (p);
        }
    }
Пример #3
0
    void renderOpenGL2D() 
    {
        LeapUtilGL::GLAttribScope attribScope( GL_ENABLE_BIT );

        // when enabled text draws poorly.
        glDisable(GL_CULL_FACE);

        ScopedPointer<LowLevelGraphicsContext> glRenderer (createOpenGLGraphicsContext (m_openGLContext, getWidth(), getHeight()));

        if (glRenderer != nullptr)
        {
            Graphics g(glRenderer);

            int iMargin   = 10;
            int iFontSize = static_cast<int>(m_fixedFont.getHeight());
            int iLineStep = iFontSize + (iFontSize >> 2);
            int iBaseLine = 20;
            Font origFont = g.getCurrentFont();

            const Rectangle<int>& rectBounds = getBounds();

            if ( m_bShowHelp )
            {
                g.setColour( Colours::seagreen );
                g.setFont( static_cast<float>(iFontSize) );

                if ( !m_bPaused )
                {
                  g.drawSingleLineText( m_strUpdateFPS, iMargin, iBaseLine );
                }

                g.drawSingleLineText( m_strRenderFPS, iMargin, iBaseLine + iLineStep );

                g.setFont( m_fixedFont );
                g.setColour( Colours::slateblue );

                g.drawMultiLineText(  m_strHelp,
                                      iMargin,
                                      iBaseLine + iLineStep * 3,
                                      rectBounds.getWidth() - iMargin*2 );
            }

            g.setFont( origFont );
            g.setFont( static_cast<float>(iFontSize) );

            g.setColour( Colours::salmon );
            g.drawMultiLineText(  m_strPrompt,
                                  iMargin,
                                  rectBounds.getBottom() - (iFontSize + iFontSize + iLineStep),
                                  rectBounds.getWidth()/4 );
        }
    void paintComponent()
    {
        if (needsUpdate)
        {
            MessageManagerLock mm (this);
            if (! mm.lockWasGained())
                return;

            needsUpdate = false;

            // you mustn't set your own cached image object when attaching a GL context!
            jassert (get (component) == this);

            const Rectangle<int> bounds (component.getLocalBounds());
            if (! ensureFrameBufferSize (bounds.getWidth(), bounds.getHeight()))
                return;

            RectangleList invalid (bounds);
            invalid.subtract (validArea);
            validArea = bounds;

            if (! invalid.isEmpty())
            {
                clearRegionInFrameBuffer (invalid);

                {
                    ScopedPointer<LowLevelGraphicsContext> g (createOpenGLGraphicsContext (context, cachedImageFrameBuffer));
                    g->clipToRectangleList (invalid);
                    paintOwner (*g);
                    JUCE_CHECK_OPENGL_ERROR
                }

                if (! context.isActive())
                    context.makeActive();
            }

            JUCE_CHECK_OPENGL_ERROR
        }
Пример #5
0
void LOpenGLComponent::renderOpenGL() {
    if(hasCallback("renderOpenGL")) {
        const float desktopScale = (float) openGLContext.getRenderingScale();
        ScopedPointer<LowLevelGraphicsContext> glRenderer(
            createOpenGLGraphicsContext ( openGLContext, 
                                            roundToInt (desktopScale * Component::getWidth()),
                                            roundToInt (desktopScale * Component::getHeight()) )
        );
        if(glRenderer != nullptr) {
            Graphics g(*glRenderer);
            g.addTransform (AffineTransform::scale (desktopScale));
            LGraphics lg(LUA::Get(), g);
            callback( "renderOpenGL", 1, { new LRefBase("Graphics", &lg) } );
            if(! LUA::isEmpty())
                renderGLSL(g);
            else
                lua_pop(LUA::Get(), 1);
        }
        else {
            callback("renderOpenGL");
        }
    }
}
Пример #6
0
 LowLevelGraphicsContext* createLowLevelContext() override
 {
     return createOpenGLGraphicsContext (context, frameBuffer);
 }
Пример #7
0
 LowLevelGraphicsContext* createLowLevelContext() override
 {
     sendDataChangeMessage();
     return createOpenGLGraphicsContext (context, frameBuffer);
 }