Page 1 of 1

C++ Read Png into opengl

Posted: 2015-06-09T14:55:57-07:00
by joessu
Very simple thing.

I am getting an odd result.

Code: Select all

Magick::Image im;
        im.magick("PNG");
        im.read(std::string(TEXTURE_DIRECTORY).append(desc.filename)); //"image.png"
        w = im.columns();
        h = im.rows();


        unsigned char* data = new unsigned char[w*h*3];
        im.write(0,0,w,h,"RGB", CharPixel, data);

        tex.widths.push_back(w);
        tex.heights.push_back(h);
        tex.texData.push_back(data);
Here is the result in OGL:

Image

looks like the format remains PNG? what am i missing?

Re: C++ Read Png into opengl

Posted: 2015-06-09T15:06:26-07:00
by magick
Perhaps the image has an alpha channel. Try w*h*4 and RGBA.

Re: C++ Read Png into opengl

Posted: 2015-06-09T15:12:50-07:00
by joessu
Ah, i thought that by declaring RGB in write that i could exclude the alpha channel?

EDIT: that didn't do it. the result is different but has same artifacts.

Re: C++ Read Png into opengl

Posted: 2015-06-10T09:35:49-07:00
by joessu
When i write it to a png using im.write("test.png"), It writes it perfectly!!!

Re: C++ Read Png into opengl

Posted: 2015-06-10T09:38:38-07:00
by joessu
Sorry for spamming, another bit of info. I know my texture code in opengl works because i was using SOIL to do the same exact thing before this

Re: C++ Read Png into opengl

Posted: 2015-06-11T13:48:39-07:00
by joessu
So the issue appears to be in my use of the pixel data after this function exits.