Using Sam Leffler's libtiff with OpenGL and GLUT


Using Sam Leffler's libtiff with OpenGL and GLUT

While OpenGL is commonly thought of as an 3D graphics library, OpenGL's texture mapping and pixel processing facilities make it an excellent hardware acceleratable image processing API as well. This page shows how to write OpenGL programs that read, display, and write TIFF image files.

TIFF stands for the Tag Image File Format. TIFF is a widely used standard for storing image data. Sam Leffler of Silicon Graphics, Inc. has written an excellent library for reading and writing TIFF files. It is fairly straightforward to use libtiff with OpenGL.

You can get the source code for libtiff for free. Like OpenGL and GLUT, libtiff is portable software and compiles on a wide variety of operating systems.

If you have libtiff, GLUT, and OpenGL (or Mesa), you can try out some of the simple image processing example programs that I have written.

showtiff.c lets you view a TIFF file in a GLUT window and move it around within the window. You can also use the pop-up menu to blur, sharpen, or edge-detect the image (this requires support of the OpenGL convolution extension). In addition to convolution operations, showtiff will convert the image to luminance (this requires support of the OpenGL color matrix extension).

The convolution and color matrix OpenGL operations are hardware accelerated on machines such as SGI's IMPACT, Octane, RealityEngine, and InfiniteReality graphics options.

You can also use libtiff to load a TIFF file as a texture. textiff.c demonstrates how to do this. The program loads a TIFF file and uses it as a texture. You can resize the window and the image resizes appropriately with texture scaling. You can also rotate the image with the left and right arrow keys. Think of texture mapping as a means to scale, rotate, project, or otherwise warp images.

Do you want to save images you've rendered with OpenGL into a TIFF file? Check out the writetiff.c example. The program renders a simple 3D scene containing gears. Use the menu options to save out gears.tif as a TIFF file (pick from several compression schemes).

- OPENGL Web site