Vertex array properties

Hi, I’m very new to OpenGL and to game programming as well. A problem that has been bugging me is how do you set some texture properties when you are goind to use glDrawElements or glDrawArrays? I know you can specify them using glTexCoordPointer, however, how about the lighting of the texture, like material ambience, material diffuse, and material specularity? I know that they can be set using glMaterial* functions, but those are only used when you are drawing using glVertex-like procedures. Please help me!

glMaterial is not only for immediate mode rendering, it’s for any rendering. So you set materials for vertex arrays exactly like you would for immediate mode rendering.

so then, for every mesh I render (with texture included), I need to call glMaterial for every glDrawArray call, am I right?

only if you want the meshes to have different colours. opengl is a “state machine”: if you call glColor (or glMaterial, or glNormal etc.), ogl “remembers” the values until the next call to glColor etc.

hmmm… I just tested it out, but it doesnt seem to work. I tested it for two different settings and it doesnt seem to be different at all.

first setting:
GLfloat MatAmb[] = {100.0f, 100.0f, 100.0f, 1.0f}; GLfloat MatDif[] = {100.0f, 100.0f, 100.0f, 1.0f}; GLfloat MatSpc[] = {100.0f, 100.0f, 100.0f, 1.0f};

and calls to glMaterial, etc, before glDrawArray

second setting:
GLfloat MatAmb[] = {0.0f, 0.0f, 0.0f, 1.0f}; GLfloat MatDif[] = {0.0f, 0.0f, 0.0f, 1.0f}; GLfloat MatSpc[] = {0.0f, 0.0f, 0.0f, 1.0f};

and calls to glMaterial, etc, before glDrawArray.

These two settings doesnt seem to be different at all! :frowning:

Please teach me to do these correctly! Thanks!

Post more code. There’s something you’re not doing right.

GLfloat MatAmb[] = {100.0f, 100.0f, 100.0f, 1.0f}; GLfloat MatDif[] = {100.0f, 100.0f, 100.0f, 1.0f}; GLfloat MatSpc[] = {100.0f, 100.0f, 100.0f, 1.0f};

doesn’t make sense. if you use floats, all material values have to be between 0.0 and 1.0

Originally posted by RigidBody:
doesn’t make sense. if you use floats, all material values have to be between 0.0 and 1.0
No. All material color components can have values in (-inf,inf) range. That the resulting primary and secondary color is clamped to <0,1> range is different matter.

I know that they can be set using glMaterial* functions, but those are only used when you are drawing using glVertex-like procedures.

You can use color-material. Enable it with glEnable(GL_COLOR_MATERIAL), then use the glColorMaterial(face, mode) call to specify which matrial property you want to set…

For example:
glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);

Then you can use the color array for the material property you specified in the color material call…

ok. its been a while now…

but how about this problem? (quoting PyOpenGL Man Pages…)

Notes
glColorMaterial makes it possible to change a subset of material parameters for each vertex using only the glColor command, without calling glMaterial. If only such a subset of parameters is to be specified for each vertex, calling glColorMaterial is preferable to calling glMaterial.

Call glColorMaterial before enabling GL_COLOR_MATERIAL.

->Calling glDrawElements, glDrawArrays, or glDrawRangeElements may leave the current color indeterminate, if the color array is enabled. If glColorMaterial is enabled while the current color is indeterminate, the lighting material state specified by face and mode is also indeterminate.

You have to ask yourself if lighting will be ON or OFF.

If ON, use glMaterial() or
glEnable(GL_COLOR_MATERIAL) and glColorMaterial()
This means that vertex color is ignored.
GL_COLOR_MATERIAL is useless. Why not just use glMaterial?

If OFF, then use glColor() or glColorArray
If you use glColorArray, after your call to glDrawRangeElements or whatever, the color will likely be the last color applied, but this is not guaranteed by GL.