Serguei Fedorov
Serguei Fedorov

Reputation: 7923

GL_INVALID_OPERATION reported by glVertexPointer even though glEnableClientState(GL_VERTEX_ARRAY) called

I am having issues with a homework which uses the OpenGL 2.0 pipeline. The issue is that I am getting and GL_INVALID_OPERATION (error 1282) when I try and setup the glVertexPointer.

I cannot find very much online to what this error, but from what I understand, this error is caused by not calling glEnableClientState(GL_VERTEX_ARRAY) before calling glVertexPointer.

Here is my code for calling both functions:

glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(4, GL_DOUBLE, sizeof(vert), (void *)0);

I have checked if the error exists before the call to glVertexPointer and the glError returns a 0 until after the call to this function. It seems like the error is being caused by something else. What are some other scenarios that may cause this issue?

I apologize for somewhat of a dry question; I just don't really know what else I can provide. If you need to see other segments of code, please let me know what I can provide.

Upvotes: 1

Views: 1158

Answers (1)

Andon M. Coleman
Andon M. Coleman

Reputation: 43319

gl___Pointer (...) will never generate a GL_INVALID_OPERATION error simply because the corresponding fixed-function client array state is not enabled. That state is used when you make a draw call like glDrawElements (...). It is not an error to specify this pointer while the array pointer is disabled.

It is, however, an error (that will generate GL_INVALID_OPERATION) to make a vertex pointer call under the three following circumstances:

  1. You have no active render context in your calling thread
  2. You are using an OpenGL 3.2 core context and have no Vertex Array Object bound
  3. You have an OpenGL 3.2 core context and are making a call to a deprecated function

Bullet points 2 and 3 will both apply to this particular API call if you have a 3.2+ core context. Vertex Array Objects are effectively an additional context that all vertex buffer bindings, array pointer and draw calls are relative to. In OpenGL 3.2 core if you do not have a Vertex Array Object bound, then these functions have no context and you could consider this situation to be a specialization of bullet point 1.

It is also an undefined operation to make a call to glVertexPointer (...) inbetween a pair of glBegin (...) and glEnd (...) calls. An implementation may or may not generate an error under these circumstances, if it does it will generate GL_INVALID_OPERATION. This applies to the vast majority of OpenGL API calls, if it does not have anything to do with specifying vertex data in immediate mode then it does not belong between glBegin (...) and glEnd (...).

The actual API reference pages (i.e. glVertexPointer (...)) never make mention of any of the three situations I outlined above. GL_INVALID_OPERATION is one of those errors like GL_OUT_OF_MEMORY that has implicit meaning, and can be generated by an entire class of API calls without ever being mentioned in the manual pages. You should familiarize yourself with the most common causes of GL_INVALID_OPERATION as such.

Upvotes: 4

Related Questions