Retrieving Information about the Texture

To draw a texture you need to know some information about the texture, such as its width, height, and color depth. The ImageDescription data structure stores relevant information about an image. You must create an ImageDescription handle and call the function GraphicsImportGetImageDescription() to get the information you need about the texture.

ComponentResult error;
ComponentInstance fileImporter;
ImageDescriptionHandle imageInfo;

imageInfo = (ImageDescriptionHandle)NewHandle(sizeof(
        ImageDescription));
error = GraphicsImportGetImageDescription(fileImporter, &imageInfo);

Getting the Texture’s Size

The ImageDescription data structure’s most important fields are width, height, and depth. You need these three fields to determine the image’s size. After calculating the image’s size, you must allocate a pointer to hold the image’s data so you can use the texture in your OpenGL application.

int width;
int height;
int depth;

width = (**imageInfo).width;
height = (**imageInfo).height;
depth = (**imageInfo).depth

unsigned long imageSize;
Ptr imageData;

imageSize = width * height * depth / 8;
imageData = NewPtr(imageSize);

Getting the Texture’s Boundary Rectangle

To draw a texture with QuickTime, you must create an offscreen buffer to hold the texture. The function to create an offscreen buffer takes a boundary rectangle as an argument. You want the buffer to match the image’s boundary rectangle. Call the function GraphicsImportGetNaturalBounds() to get the image’s boundary rectangle.

Rect imageRect;
ComponentResult error;
    
error = GraphicsImportGetNaturalBounds(fileImporter, &imageRect);

Next (Drawing the Texture)

Previous (Opening the Graphics Importer)