Last modified on 4 December 2013, at 16:30

OpenGL Programming/Basics/NamingConventions

Naming ConventionsEdit

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 FunctionsEdit

OpenGL functions are always named in the following manner:

OpenGLFunctionNamingConventions.jpg

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 ArgumentsEdit

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:

glVertex2f(float x, float y)

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

glVertex3f(float x, float y, float z)

or with integers instead of floats:

glVertex3i(int x, int y, int z)

or with an array of three floats:

glVertex3fv(float * array)

OpenGL Data TypesEdit

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.