I'm doing some pixel work in OpenGL, and all was going well until I had to load a PNG. I found a thing called 'DevIL', and followed an example I found. It does display something, but it's just kind of a random rainbow. I'm doing it right as far as I can tell; I output the data to a text file to check it. I tried some other libraries, but building them is a little beyond my capabilities. Here's my setup:
((In global scope))
unsigned char pixels[160000*3];
ILubyte * bytes ;
((Main))
ilInit();
ilLoadImage( "test.png" ) ;
size = ilGetInteger( IL_IMAGE_SIZE_OF_DATA ) ;
bytes = ilGetData() ;
And here's my drawing routine:
//Color the screen all pretty
for(int i=0;i<160000*3;)
{
pixels[i] = a;
i++;
pixels[i] = b;
i++;
pixels[i] = c;
i++;
}
//Break the png
for( int i = 0 ; i < size;)
{
if(bytes[i+3] != 255)
{ i+=4;
continue; }
pixels[i] = bytes[i];
i++;
pixels[i] = bytes[i];
i++;
pixels[i] = bytes[i];
i++;
i++;
}
glDrawPixels(
400,
300,
GL_RGB,
GL_UNSIGNED_BYTE,
pixels
);
I know the alignment is wrong; I'll fix that later. The problem is the colors are totally not right
P.S. I know you're supposed to use textured quads
PNG is a compressed format. Seems like ilGetData returns pointer to a compressed data. To get decoded image use ilCopyPixels.