Core 4.2 and use of VertexAttrib{1234}{sfd}(...)

Reading through the opengl42-quick-reference-card.pdf in the “Vertex Specification” section, I became curious what purpose the glVertexAttrib* serve. It seems that with glVertexAttribPointer in the “Vertex Arrays” section the entire “Vertex Specification” section is pointless in terms of core context.

In the process of reading more, Post268973 showed an example of these glVertexAttrib* functions replacing glVertex, glColor, etc in a more general way. But to be useful the post seemed to demonstrate that glVertexAttrib* require immediate mode (glBegin()/glEnd()) which are no longer in the core.

So the question is what are glVertexAttrib* used for in core without glBegin/glEnd? Note that glVertexAttrib* in the section “Vertex Specification” is different than the glVertexAttribPointer in the “Vertex Arrays” section. I understand the value of glVertexAttribPointer but not the glVertexAttrib{1234}{sfd}(…) function for instance.

The glVertexAttrib methods can be used without glBegin/glEnd. They allow you to set a uniform value for a vertex array input, rather than using an array. This can come in handy if you want to define a vertex shader input that may be varying or constant.

glVertexAttrib sets the current value to be used when an attribute is disabled.

As noted by other people, the behaviour for attribute 0 in the core profile is different to in a compatibility profile. In a compatibility profile glVertexAttrib(0, …) issues a vertex similar to glVertexNN, so can only be used inside glBegin/glEnd (similar to how you can call glColor/glTexCoord etc outside glBegin/glEnd but not glVertex), but in the core profile it behaves the same way as all the other attributes (it sets a current value), so is usable outside glBegin/glEnd (which don’t exist).

Also, I’ve just noticed that since OpenGL 4.2, the current value for attributes is guaranteed not to be modified when drawing, but prior to 4.2, drawing left the current values for enabled attributes undefined.

Thanks. That helps clarify the use of the glVertexAtrib* functions. I hadn’t considered what happens if an attribute is disabled or having a need for a constant attribute sometimes.