Cleaning Up

When you’re finished loading the texture you must dispose of the memory you allocated and close the graphics importer. You allocated a pointer to hold the image data and allocated two handles, one for the image information and one for the QuickTime data reference.

OSErr error;

error = CloseComponent(fileImporter);
DisposeHandle((Handle)imageInfo);
DisposeHandle(dataRef);

if (imageData != NULL) {
    DisposePtr(imageData);
    imageData = NULL;
}
    
if (offscreenBuffer != NULL) {
    DisposeGWorld(offscreenBuffer);
    offscreenBuffer = NULL;
}

DisposeGWorld() is a QuickDraw function, which was deprecated in Mac OS X 10.4. You will get a warning when you build your project.

Conclusion

I included some sample code that draws a texture on the screen. The most interesting code is in the GameTexture.cpp file. To learn more about OpenGL texture mapping, go to the OpenGL site. It includes online versions of the OpenGL Programming Guide (the red book) and the OpenGL Reference Manual (the blue book). Another good place for OpenGL information is the NeHe Productions website. It has a series of OpenGL tutorials that many people have found helpful.

Previous (Specifying the Texture in OpenGL)