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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.