To make it easier to port OpenGL code from one platform to another, OpenGL defines its own data types. These data types map to normal C data types that you can use instead, if desired. The various compilers and environments, however, have their own rules for the size and memory layout of various C variables. By using the OpenGL defined variable types, you can insulate your code from these types of changes.
Table 3-2 lists the OpenGL data types, their corresponding C data types under the 32-bit Windows environments (Win32), and the appropriate suffix for literals. In this book we will use the suffixes for all literal values. You will see later that these suffixes are also used in many OpenGL function names.
All data types start with a GL to denote OpenGL. Most are followed by their corresponding C data types (byte, short, int, float, etc.). Some have a u first to denote an unsigned data type, such as ubyte to denote an unsigned byte. For some uses a more descriptive name is given, such as size to denote a value of length or depth. For example, GLsizei is an OpenGL variable denoting a size parameter that is represented by an integer. The clamp is used for color composition and stands for color amplitude. This data type is found with both f and d suffixes to denote float and double data types. The GLboolean variables are used to indicate True and False conditions, GLenum for enumerated variables, and GLbitfield for variables that contain binary bit fields.
Pointers and arrays are not give any special consideration. An array of ten GLshort variables would simply be declared as
and an array of ten pointers to GLdouble variables would be declared with
Some other pointer object types are used for NURBS and Quadrics. They take more explanation and will be covered in later chapters.
OpenGL functions all follow a naming convention that tells you which library the function is from, and often how many and what type of arguments the function takes. All functions have a root that represents the function’s corresponding OpenGL command. For example, the glColor3f() function has the root Color. The gl prefix represents the gl library (see Table 3-1), and the 3f suffix means the function takes three floating point arguments. All OpenGL functions take the following format:
<Library prefix><Root command><Optional argument count><Optional argument type>
Figure 3-1 illustrates the parts of an OpenGL function. This sample function with the suffix 3f takes three floating point arguments. Other variations take three integers (glColor3i()), three doubles (glColor3d()), and so forth. This convention of adding the number and type of arguments (see Table 3-1) to the end of OpenGL functions makes it very easy to remember the argument list without having to look it up. Some versions of glColor take four arguments to specify an alpha component, as well.
In the reference sections of this book, these “families” of functions are listed by their library prefix and root. Thus all the variations of glColor (glColor3f, glColor4f, glColor3i, etc.) will be listed under a single entry—glColor.