Bug when trying to draw sub section of OpenGLImageType

I'm trying to use the OpenGLImageType class but it won't display when I try to draw just a subsection of the image.

Here's a small MainComponent that reproduces the problem.


class MainContentComponent   : public Component, public OpenGLRenderer




    void paint (Graphics&) override;

    void newOpenGLContextCreated() override;

    void renderOpenGL() override;

    void openGLContextClosing() override;    



    OpenGLContext _context;    

    Image _image;









    setSize (600, 400);    




void MainContentComponent::paint (Graphics& g)





                0, 0, getWidth(), getHeight(),

                0, 0, _image.getWidth() / 2, _image.getHeight() / 2);



void MainContentComponent::newOpenGLContextCreated()


    auto cpuImage = ImageCache::getFromMemory(BinaryData::canvas1_png, BinaryData::canvas1_pngSize);

    _image = OpenGLImageType().convert(cpuImage);


void MainContentComponent::renderOpenGL()



void MainContentComponent::openGLContextClosing()




This code works as expected when using an image created directly from ImageCache::getFromMemory(...) but the image doesn't display when using OpenGLImageType.  This has been tested using the latest juce on OSX

After a bit more testing, I found this also fails when using sub images got from Image::getClippedImage()

Like I replied on the other thread: You can't call any openGL functions (even indirectly via the OpenGLImageType) in the paint callback, because doing so will mess-up the GL context state which the renderer is using. You need to do this kind of thing in renderOpenGL() or newOpenGLContextCreated()

I read your reply and have been trying to move everything to standard juce code so I could keep using paint().  I read here: http://www.juce.com/forum/topic/opengl-performance-windows?page=1 (post #19) that you recommended drawing an OpenGLImageType image in the paint method - is this no longer recommended?

Everything else now seems to work as expected except drawing only part of the image.

To be honest since we recently added GL texture caching, there's not a lot of point in using an OpenGLImageType unless you actually need to draw into it using GL. If you just use a normal image then the first time you draw it, it'll get automatically cached as a texture, so will be very fast to draw it subsequently.