OpenGL Programming/Basics/NamingConventions

Naming Conventions
Now that we've used some OpenGL functions, it's time we understood what those 3fs meant in those functions we've been using.

OpenGL Functions
OpenGL functions are always named in the following manner:




 * First comes the prefix. In this example, gl- refers to a built-in OpenGL function. Functions from GLUT will be prefixed with glut- instead. Later, we'll see that GLU functions are similarly prefixed with glu-.


 * This is followed by the actual function name. Here, we're changing a color, so we provide Color as our function name.


 * Next comes the number of arguments we plan to give to the function. Here we want to give it 3 arguments, so we write 3. In functions with an unfixed number of arguments (e.g. glTranslatef), this number is omitted.


 * Following the number of arguments, we have the type of arguments we plan to give. This can be either b, s, i, f or d in most cases, standing for byte, short, integer, float or double respectively. Use ub, us, ui for unsigned byte, short or integer. Append a v here to pass an array instead of separate arguments.


 * Finally, we have the actual arguments.

Pick Your Battles, Pick Your Arguments
Many functions are available with a different number of arguments. For example, the function glVertex2f which we used in the last chapter takes 2 float parameters, x and y:

gl Vertex 2 f (float x, float y)

may also be called with a third parameter, z, by using:

gl Vertex 3 f (float x, float y, float z)

or with integers instead of floats:

gl Vertex 3 i (int x, int y, int z)

or with an array of three floats:

gl Vertex 3 fv (float * array)

OpenGL Data Types
OpenGL defines some data types that are preferable to the built-in C data types. The more commonly used ones are:


 * GLenum
 * GLboolean
 * GLvoid
 * GLbyte
 * GLshort
 * GLint
 * GLubyte
 * GLushort
 * GLuint
 * GLsizei
 * GLfloat
 * GLdouble

Most of these are self explanatory. GLenum refers to a constant, and any type that starts with u means unsigned. All these types are equivalent but preferable to their C counterparts when writing OpenGL code.