Some Simple OGL tests


#1

I’ve been trying to track down problems with using OGL for the UI. Firstly, there is a horrible screen corruption problem on Android (fine on windows) and secondly, the processing and reacting to events is slower when using OGL to draw (could be thread related).

Here’s my exciting “red box” test.

MainComponent.h

[code]#include “…/JuceLibraryCode/JuceHeader.h”

class Panel : public Component
{
public:
Panel(const Colour& c) : _col© {}

void paint(Graphics& g)
{
    g.fillAll(_col);
}

void _init()
{
    setOpaque(true);
}    

Colour _col;

};

class RedBox: public Panel
{
public:

RedBox() : Panel(Colours::red)
{
    _init();
}

void mouseDown(const MouseEvent&)
{
    _downPos = getPosition();
}

void mouseDrag(const MouseEvent& e)
{
    Point<int> dp = e.getOffsetFromDragStart();
    setTopLeftPosition(_downPos + dp);
}

private:

Point<int>          _downPos;

};

class MainContentComponent : public Component, public OpenGLRenderer
{
public:

MainContentComponent()
{
    setSize(800,600);
    _init();
}

~MainContentComponent()
{
    _purge();
    _glCtx.detach();
}

void paint(Graphics& g)
{
    g.fillAll(Colours::white);
}

// OpenGLRenderer, compliance
void newOpenGLContextCreated() {}
void renderOpenGL() {}
void openGLContextClosing() {}

private:

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)

void _init()
{
     // COMMENT out these two lines to disable OGL drawing
    _glCtx.setRenderer(this);
    _glCtx.attachTo(*this);
}

void _purge()
{
    while (getNumChildComponents())
    {
        Component* c = getChildComponent(0);
        removeChildComponent(0);
        delete c;
    }
}

OpenGLContext             _glCtx;

};
[/code]

Its very simple. it creates a red box component which you can move with your finger.

I create it like this in my MainWindow,

[code] MainContentComponent* mc = new MainContentComponent();

        RedBox* rb = new RedBox;
        int sz = 200;
        rb->setBounds(20,20,sz,sz);
        mc->addAndMakeVisible(rb);

        setContentOwned (mc, true);

#ifdef JUCE_ANDROID
setFullScreen(true);
#else
centreWithSize (getWidth(), getHeight());
#endif
setVisible (true);

[/code]

Under windows everything is fine, but under android the box disappears when you move it. It has the same look as “z-fighting”, but how can this be on a 2D projection. or can it?

The other problem is that the movement lag, ie the time between moving your finger and the box moving is greater when using OGL (ie worse). This phenomenon is the case for all builds right now.

To change between OGL drawing and normal, comment in or out the lines after the marker

ideas welcome. thanks,