Loading Images from Files

The simple example of directly storing image data in arrays in your “C” code (or from buffer objects) isn’t very practical if you have large images stored on disk. In most applications, you’ll store your texture data in a formatted image file—a JPEG, PNG, GIF, or other type for image format—OpenGL works either with raw pixels or with textures compressed with specific algorithms. As such, your application will need to decode the image file into memory that OpenGL can read to initialize its internal texture store. To simplify that process for our examples, we wrote a function, vglLoadImage(), which will read an image file,8 and return the texels in memory, along with other information you’ll need to help OpenGL to decode ...

Get OpenGL Programming Guide: The Official Guide to Learning OpenGL, Version 4.3, Eighth Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.