OpenGL texture from png


#1

Hi everyone,

i am using JUCEs OpenGLTexture to load from images. With jpgs it is working perfectly but when i try to use the same process with pngs i am getting GL_INVALID_VALUE. My steps are:

1) using Introjucer to load the image into a component

2) ImageCache::getFromMemory(... , ...) to create the Image

3) OpenGLTexture::loadImage(image)

Anyone has a similar experience?

Best,

Thomas


#2

A few questions / things to try:

1) Are you on the latest tip? If you're not, you update and try again.

2) Have you tried a different source image? Your image might be corrupted.

3) If you've tried both of the above, please provided a minimal example we can use to reproduce the issue (perhaps by posting the complete code on GitHub). The keyword here is minimal; if you dump hundreds of lines of user code we're not going to have time to read it :)

Hope this helps!


#3

It's a bit difficult to paste sufficient code here, but to reproduce the problem you can do the following:

Open the OpenGLAppExamples Introjucer file and add a GUI component naming it t. Then add a jpg and a png to this GUI component.

Then add the following lines in MainComponent.cpp (replacing initialise(){...}):

OpenGLTexture texture;

    void initialise() override
    {
        createShaders();
        texture.bind();
        Image im = ImageCache::getFromMemory(t::mypic_png, t::mypic_pngSize);
        texture.loadImage(im);
    }

Watch the console for the error message. If you choose the jpg instead, the error msg does not appear.

If you then try to use the texture later in your code, it will be only visible when loaded from the jpg, not from the png.

Best,

Thomas


#4

I can't seem to reproduce this (tried on Windows 10 and Linux). This is what I tried:

 


 void initialise() override
    {
        texture.bind();
#if 0
        Image im = ImageCache::getFromMemory(BinaryData::wood_jpg, BinaryData::wood_jpgSize);
#else
        Image im = ImageCache::getFromMemory(BinaryData::wood_png, BinaryData::wood_pngSize);
#endif
        texture.loadImage (im);
    }
    void render() override
    {
        OpenGLHelpers::clear (Colours::black);
        glDisable(GL_LIGHTING);
        glColor3f(1, 1, 1);
        glEnable(GL_TEXTURE_2D);
        texture.bind();
        // Draw a textured quad
        glBegin(GL_QUADS);
        glTexCoord2f(0, 0); glVertex3f(0, 0, 0);
        glTexCoord2f(0, 100); glVertex3f(0, 100, 0);
        glTexCoord2f(100, 100); glVertex3f(100, 100, 0);
        glTexCoord2f(100, 0); glVertex3f(100, 0, 0);
        glEnd();
    }

 


#5

Ah, i forgot to mention, i am on Mac, El Capitan. Haven't tried it on Yosemite ...


#6

News:

It seemed to have something to do with the size of the image. I wanted to load a texture to use it as a filmstrip and its size was 18800 x 412. After reducing it to 1880 x 41 it worked.

Are there any size limits i should know of?

Best,

Thomas


#7

Check the maximum OpenGL texture size (gfx card specific) to determine the maximum size of images you can load.


int maxSize = 0;
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &maxSize);

#8

Thanks,

but what makes the thing curious is that a jpg with the same dimensions did load correctly while a png did not.

Best,

Thomas


#9

Didn't you debug your code to see exactly what it was that failed??

Maybe it had nothing to do with openGL, maybe the png didn't even load? Could be that the png loader classes can't handle that size, or have a sanity-check limit in there somewhere.