View Full Version : Size of glMaterialfv and glLightfv array

12-03-2012, 12:04 PM
I am using glMaterialfv and glLightfv to set the material and lights properties of an object.
I have a doubt about the size of the array that have to be passed as argument, the documentation I'm reading doesn't say anything about that.
For example:

glMaterialfv(GL_FRONT, GL_SHININESS, (const GLfloat[]) {1,0,0,0} );

But what if I pass an array of 3 glFloat's? Can this be done? And how do I change the format to choose if I want to pass a RGBA array or RGB?

12-03-2012, 12:42 PM
I hope your example is just that, and not any code you're actually using.

glMaterialfv takes different arrays depending on the parameter name: in particular, GL_SHININESS takes an array of length 1, with the single value between 0 and 128.

The rest (GL_AMBIENT, GL_DIFFUSE, GL_SPECULAR, GL_EMISSION, GL_AMBIENT_AND_DIFFUSE) take arrays of length 4 (RGBA). The fourth element of the array is the alpha value.

Depending on your binding there may be differences, but as far as I know, the C language binding only takes arrays of length 4. If you need just RGB, keep in mind that an RGBA array with alpha of 1.0f is the same thing.

EDIT: I forgot to mention the parameter name GL_COLOR_INDEXES, which takes an array of length 3. However, this array does not represent an RGB color, but rather ambient, diffuse, and specular indexes for the OpenGL lighting model.