Explicitly Setting Texture Data

In order to describe the process in which texture data is specified to OpenGL, it’s possibly easiest to be able to see the image data directly in your program. Texture data is laid out6 as you might expect it to be—left to right, top to bottom. In Example 6.1, texture data is stored in a constant array declared in C.

6. There are several parameters supported by OpenGL that allow you to change the layout of image data in memory. These are discussed later in this chapter, but the defaults are sufficient for this example.

Example 6.1. Direct Specification of Image Data in C

// The following is an 8x8 checkerboard pattern using// GL_RED, GL_UNSIGNED_BYTE data.static const GLubyte tex_checkerboard_data[] ...

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.