#include "imgtex.h" // Apple's annoying non-standard include locations #if defined(__APPLE__) || defined(MACOSX) #include #include #include #else #include #include // Untested: I have no clue if this is correct #endif #include #include void loadIMG(std::string fname, int texUnit) { // Create file spec FSRef fr; FSSpec fs; Boolean dir; if (FSPathMakeRef((const UInt8*)(fname.c_str()),&fr,&dir) != noErr || dir || FSGetCatalogInfo(&fr,kFSCatInfoNone,0,0,&fs,0) != noErr) { fprintf(stderr,"Error opening %s\n",fname.c_str()); return; } // get file info GraphicsImportComponent gc; GetGraphicsImporterForFile(&fs, &gc); ImageDescriptionHandle id=(ImageDescriptionHandle)NewHandle( sizeof(ImageDescriptionHandle)); GraphicsImportGetImageDescription(gc,&id); int w=(*id)->width; // image width int h=(*id)->height; // image height int c=((*id)->depth+7)/8; // bytes per pixel // flip vertically Rect r = {w,h,0,0}; GraphicsImportSetBounds(gc, &r); GraphicsImportSetQuality(gc,codecLosslessQuality); // create image block std::auto_ptr imdata(new char[w*h*c]); GWorldPtr gw; Rect wr = {0,0,w,h}; printf("%s:%d\n", __FILE__,__LINE__); // import printf("%s:%d\n", __FILE__,__LINE__); LockPixels(GetGWorldPixMap(gw)); printf("%s:%d\n", __FILE__,__LINE__); GraphicsImportDraw(gc); printf("%s:%d\n", __FILE__,__LINE__); UnlockPixels(GetGWorldPixMap(gw)); printf("%s:%d\n", __FILE__,__LINE__); // clean up DisposeGWorld(gw); printf("%s:%d\n", __FILE__,__LINE__); CloseComponent(gc); printf("%s:%d\n", __FILE__,__LINE__); SetGWorld(origPort, origDevice); printf("%s:%d\n", __FILE__,__LINE__); // load into texture GLenum formats[] = {0,GL_LUMINANCE,GL_LUMINANCE_ALPHA,GL_RGB,GL_RGBA}; glActiveTexture(GL_TEXTURE0 + texUnit); glBindTexture(GL_TEXTURE_2D,texUnit+1); glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); gluBuild2DMipmaps(GL_TEXTURE_2D,c,w,h,formats[c], GL_UNSIGNED_BYTE, imdata.get()); glEnable(GL_TEXTURE_2D); } void dumpIMG(std::string fname, int x, int y, int w, int h) { // // get data // std::auto_ptr imdata(new png_byte[w*h*3]); // std::auto_ptr imrow(new png_byte*[h]); // for(int i=0; i