Jump to content

  • Log In with Google      Sign In   
  • Create Account

glVertexAttribPointer giving GL_INVALID_OPERATION


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 Nairou   Members   -  Reputation: 431

Like
0Likes
Like

Posted 04 September 2011 - 02:06 AM

I don't get it. Everything was working fine earlier, now the following code fragment won't even work. According to gDEbugger, I get a GL_INVALID_OPERATION on the glVertexAttribPointer() call. But I don't see anything wrong with it.

Note: I'm using the GLFW and GLEW libraries.



struct quadFormat_s
{
	float x;
	float y;
	float z;
	float u;
	float v;
};

quadFormat_s quadVertex[] = {
	{-1.0f, -1.0f, 1.0f, 0.0f, 1.0f},
	{-1.0f, 1.0f, 1.0f, 0.0f, 0.0f},
	{1.0f, 1.0f, 1.0f, 1.0f, 0.0f},
	{1.0f, -1.0f, 1.0f, 1.0f, 1.0f}
};



glfwInit();

glfwOpenWindowHint( GLFW_OPENGL_VERSION_MAJOR, 3 );
glfwOpenWindowHint( GLFW_OPENGL_VERSION_MINOR, 2 );
glfwOpenWindowHint( GLFW_OPENGL_FORWARD_COMPAT, true );
glfwOpenWindowHint( GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE );

glfwOpenWindow( 1024, 768, 8, 8, 8, 8, 24, 0, GLFW_WINDOW );

glewInit();

glGenBuffers( 1, &vboVertexQuad );
glBindBuffer( GL_ARRAY_BUFFER, vboVertexQuad );
glBufferData( GL_ARRAY_BUFFER, quadVertexCount*sizeof(quadFormat_s), quadVertex, GL_STATIC_DRAW );
glVertexAttribPointer( 0, 3, GL_FLOAT, GL_FALSE, sizeof(quadFormat_s), reinterpret_cast<void*>(0 + 0) );

The weird thing is, it starts working fine if I change my OpenGL context to 3.1 (instead of 3.2) and backward compatible (instead of forward compatible).

Am I missing something obvious, or has my computer gone crazy?

Sponsor:

#2 i_luv_cplusplus   Members   -  Reputation: 250

Like
0Likes
Like

Posted 04 September 2011 - 02:33 AM

Where is your glewInit() call? It should be before glBindBuffer and after glfwOpenWindow
OpenGL fanboy.

#3 V-man   Members   -  Reputation: 805

Like
1Likes
Like

Posted 04 September 2011 - 06:16 AM

If you are using core profile on GL 3.2, then you must use VAO when you call glBindBuffer and glVertexAttribPointer.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

#4 Nairou   Members   -  Reputation: 431

Like
0Likes
Like

Posted 04 September 2011 - 09:33 AM

If you are using core profile on GL 3.2, then you must use VAO when you call glBindBuffer and glVertexAttribPointer.

VAO? Vertex arrays? I thought vertex arrays were older and got replaced by VBOs. Weird. Do you have any links where I can get more info on these functions requiring VAOs? The OpenGL man page doesn't mention it as far as I can tell.

#5 Nairou   Members   -  Reputation: 431

Like
0Likes
Like

Posted 04 September 2011 - 09:37 AM

Where is your glewInit() call? It should be before glBindBuffer and after glfwOpenWindow

Woops, looks like I accidentally cut that out while trying to find the minimum amount of code to reproduce the problem. Even with that line, I get the same result. I've edited my code snippet.

#6 Brother Bob   Moderators   -  Reputation: 8576

Like
1Likes
Like

Posted 04 September 2011 - 09:55 AM


If you are using core profile on GL 3.2, then you must use VAO when you call glBindBuffer and glVertexAttribPointer.

VAO? Vertex arrays? I thought vertex arrays were older and got replaced by VBOs. Weird. Do you have any links where I can get more info on these functions requiring VAOs? The OpenGL man page doesn't mention it as far as I can tell.

To clarify the terms here:
  • Vertex arrays (VA) is the mechanism by which you store objects in arrays and draw vertices in batches. Vertex arrays are most certainly not old and replaced. It is, in fact, the only way to draw something today.
  • Vertex buffer object (VBO) is an object that stores vertex array data. It is the OpenGL equivalent to, for example, new[] or malloc. Its only purpose is to provide storage for your vertex arrays.
  • Vertex array objects (VAO) is an object that stores VBO bindings. You can see it as an object that stores calls to glVertexAttribPointer and glEnableVertexAttribArray so you can quickly re-bind and enable a set of arrays by binding the VAO object, instead of binding several VBO objects and resetting pointers for ever attribute.
All three of these are quite useless on their own today, but they all exist to work together. For example, in previous versions you could use VAs alone by passing pointers to your own memory. That is not possible anymore, and now you need store the vertex arrays in a VBO instead.

The functions for VAO you want to look for are glGenVertexArrays and glBindVertexArray.

#7 V-man   Members   -  Reputation: 805

Like
0Likes
Like

Posted 04 September 2011 - 04:33 PM

http://www.opengl.org/wiki/Tutorial1:_Rendering_shapes_with_glDrawRangeElements,_VAO,_VBO,_shaders_%28C%2B%2B_/_freeGLUT%29
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

#8 Nairou   Members   -  Reputation: 431

Like
0Likes
Like

Posted 04 September 2011 - 05:52 PM

@Brother Bob
Thanks for the clarification! I don't know why the OpenGL documentation is so vague, the man pages for those two functions you mention say almost nothing.

However, I was able to find a wiki article (http://www.opengl.or...e_(C%2B%2B/Win)) which illustrated it pretty well.

My test program is once again working normally. Thanks!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS