+
+
+void
+SGTexture::read_rgba_texture(const char *name)
+{
+ GLubyte *ptr;
+ GLubyte *rbuf, *gbuf, *bbuf, *abuf;
+ SGTexture::ImageRec *image;
+ int y;
+
+ if (texture_data)
+ delete texture_data;
+
+ image = ImageOpen(name);
+ if(!image)
+ return;
+
+ texture_width = image->xsize;
+ texture_height = image->ysize;
+ if (image->zsize != 3 && image->zsize != 4) {
+ ImageClose(image);
+ return;
+ }
+
+ texture_data = new GLubyte[ image->xsize * image->ysize * 4 ];
+ rbuf = new GLubyte[ image->xsize ];
+ gbuf = new GLubyte[ image->xsize ];
+ bbuf = new GLubyte[ image->xsize ];
+ abuf = new GLubyte[ image->xsize ];
+ if(!texture_data || !rbuf || !gbuf || !bbuf || !abuf) {
+ delete texture_data;
+ delete rbuf;
+ delete gbuf;
+ delete bbuf;
+ delete abuf;
+ return;
+ }
+
+ ptr = texture_data;
+ memset(abuf, 255, image->xsize);
+ for(y=0; y<image->ysize; y++) {
+ if(image->zsize == 4) {
+ ImageGetRow(image,rbuf,y,0);
+ ImageGetRow(image,gbuf,y,1);
+ ImageGetRow(image,bbuf,y,2);
+ ImageGetRow(image,abuf,y,3);
+ rgbatorgba(rbuf,gbuf,bbuf,abuf,ptr,image->xsize);
+ ptr += (image->xsize * 4);
+ } else {
+ ImageGetRow(image,rbuf,y,0);
+ ImageGetRow(image,gbuf,y,1);
+ ImageGetRow(image,bbuf,y,2);
+ rgbatorgba(rbuf,gbuf,bbuf,abuf,ptr,image->xsize);
+ ptr += (image->xsize * 3);
+ }
+ }
+
+ ImageClose(image);
+ delete rbuf;
+ delete gbuf;
+ delete bbuf;
+ delete abuf;
+}
+