PDA

View Full Version : glVertexPointer, ivalid operation in gl 3.2 ?



lobbel
06-02-2010, 04:43 PM
Hello,
I created a opengl context, version 3.2.
When I call glVertexPointer, glGetError returns
the error 1282 (0502hex) and is defined as
INVALID_OPERATION.

Here's that piece of code where the error occurs.



_create(vertexbufferId, indexbufferId);
/* bind buffers buffer */
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vertexbufferId);
glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, indexbufferId);
/* init buffers, allocate memory */
glBufferDataARB(GL_ARRAY_BUFFER_ARB, vbSize, NULL, GL_STATIC_DRAW);
glBufferDataARB(GL_ELEMENT_ARRAY_BUFFER_ARB, ibSize, NULL, GL_STATIC_DRAW);

glVertexPointer(3, GL_FLOAT, 12 * sizeof(float), BUFFER_OFFSET(0));
-> here, glGetError brings the code INVALID_OPERATION.



Then I used glewGetErrorString(...) but I didnt get a description, just "Unknown error".

regards,
lobbel

Alfonse Reinheart
06-02-2010, 07:42 PM
Unless you have created a compatibility context, functions that were removed from GL 3.1 are not available in 3.2. So add the appropriate compatibility flag to your context creation flags, and try again.

lobbel
06-03-2010, 12:24 AM
Hello,
I thought VBO have not been removed. And when I use VBO
with an indexbuffer so that I can use glDraw(Range)Elements
I need to use glVertexPointer.

regards,
lobbel

Ilian Dinev
06-03-2010, 12:47 AM
glVertexPointer was removed, not VBOs...

Dark Photon
06-03-2010, 04:24 AM
glVertexPointer was removed, not VBOs...
And in case that doesn't clinch it for you, what was deprecated are what's termed "legacy" or "fixed-function" vertex attributes. For vertex arrays, that means gl{Vertex,Normal,Color,TexCoord}Pointer, etc. along with the associated gl{Enable,Disable}ClientState( GL_{VERTEX,NORMAL,COLOR,TEXTURE_COORD}_ARRAY ) enable flags.

Instead, use glVertexAttribPointer and gl{Enable,Disable}VertexAttribArray.

The main difference is that now vertex attributes are identified by number, not by hard-coded-into-the-API-name.

Of course, you can just create a compatibility context if you want to play with the deprecated APIs for a bit while you get used to the newer APIs.

lobbel
06-03-2010, 06:12 AM
Thanks,
I got it. After reading the quick reference guide and a tutorial.
I read this tutorial http://www.opengl.org/wiki/Tutorial:_OpenGL_3.1_The_First_Triangle_%28C%2B%2B/Win%29

And in this tutorial there are two vbo's. The first for
vertex coordinates and the second for colors. So far so
good the tutorial works. But then I wanted to put the vertex
coordinates and the colors in one vbo.



float vert[18] = { 0.0f, 1.0f, -1.0f,
-0.8f, -0.8f, -1.0f,
0.8f, -0.8f, -1.0f,
1.0f, 0.0f, 0.0f,
0.0f, 1.0f, 0.0f,
0.0f, 0.0f, 1.0f
};

glGenBuffers(2, &vb);
glBindBuffer(GL_ARRAY_BUFFER, vb);
glBufferData(GL_ARRAY_BUFFER, sizeof(vert), vert, GL_STATIC_DRAW);


For drawing I call this..



glBindBuffer(GL_ARRAY_BUFFER, vb[0]);
glVertexAttribPointer(shader.getAttribLocation("in_Position"), 3, GL_FLOAT, GL_FALSE, 0, 0);
glEnableVertexAttribArray(shader.getAttribLocation ("in_Position"));
glVertexAttribPointer(shader.getAttribLocation("in_Color"), 3, GL_FLOAT, GL_FALSE, 9*sizeof(float), 0);
glEnableVertexAttribArray(shader.getAttribLocation ("in_Color"));
shader.bind();
glDrawArrays(GL_TRIANGLES, 0, 3);
shader.unbind();

glDisableVertexAttribArray(shader.getAttribLocatio n("in_Position"));
glDisableVertexAttribArray(shader.getAttribLocatio n("in_Color"));
glBindBuffer(GL_ARRAY_BUFFER_ARB, 0);



Well, this draws the triangle but the blue color is missing.
Actually the colors of the triangle vertices are


red

green blue

But putting the vertices and colors in one vbo it looks like

green
red black

The first 9 float values are the vertices and the left 9 values
are the color values. So for the color vertexattributepointer
I set the stride to 9 * sizeof(float)
glVertexAttribPointer(shader.getAttribLocation("in_Color"), 3, GL_FLOAT, GL_FALSE, 9*sizeof(float), 0);

Can someone tell me what I did wrong ?

best regards,
lobbel

lobbel
06-03-2010, 06:48 AM
Solved,
I missed to set the offset for the components.

regards,
lobbel