But it seems this method can load virtually any bitmap image data.
More exactly, any image format supported by Cocoa. DDS files, for example, won't work. Unless you include a NSImageRep for the DDS file format.
I find it hard to understand the role of NSBitmapRep and NSBitmapImageRep. I can't understand how does this code converts the image data from tga or jpg or anything else to plain unsigned bytes that OpenGL needs.
To be honest, I never took the time to try to understand: it worked
I just read the NSImage and NSBitmapImageRep documentation, here is what I understand:
when using -initWithContentsOfFile, NSImage will look for a NSImageRep capable of loading the image file, based on the file extension. So, NSImage is a class to handle any kind of images, and it is NSImageRep that actually deals with the various file format. And, unless you want to load an image in a format not supported by Cocoa, you don't have to deal with NSImageRep.
Next, the code gets a NSBitmapImageRep from the NSImage. As the name implies, NSBitmapImageRep is a bitmap, and will let you access the raw pixels. -TIFFRepresentation returns a TIFF bitmap using no compression. Which means that the NSBitmapImageRep contains "the plain unsigned bytes" that can be sent to GL.