Original Post
I kind of adapted one of NeHe's tutorials that teaches how to load RAW images, because I need a function to load images with an alpha channel. I'm not sure how PNGs are stored, or where to look, so I would be VERY appreciative if you could look at this source and tell me if I'm on the right track... Thanks!
typedef struct tagTEXTURE_IMAGE
{
int width;
int height;
int format;
unsigned char* data;
} TEXTURE_IMAGE;
typedef TEXTURE_IMAGE * P_TEXTURE_IMAGE;
bool LoadPNG(const char * filename, P_TEXTURE_IMAGE buffer)
{
int width = buffer->width;
int height = buffer->height;
int format = buffer->format;
ifstream fin(filename, ifstream::binary);
int stride = width * format;
unsigned char* p=NULL;
char c;
int done=0;
if (!fin)
return false;
//We have successfully loaded into 'fin'
for (unsigned i=0; i<height; ++i)
{
p = buffer->data + (i * stride);
for (unsigned j=0; j<width; ++j)
{
for (unsigned k=0; k<format; ++k, ++p, ++done)
{
fin.get(c);
*p = c;
}
}
}
fin.close();
return true;
}