Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 7 of 7

Thread: glVertexPointer, ivalid operation in gl 3.2 ?

  1. #1
    Junior Member Regular Contributor
    Join Date
    Sep 2008
    Posts
    139

    glVertexPointer, ivalid operation in gl 3.2 ?

    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.

    Code :
    _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

  2. #2
    Senior Member OpenGL Lord
    Join Date
    May 2009
    Posts
    6,070

    Re: glVertexPointer, ivalid operation in gl 3.2 ?

    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.

  3. #3
    Junior Member Regular Contributor
    Join Date
    Sep 2008
    Posts
    139

    Re: glVertexPointer, ivalid operation in gl 3.2 ?

    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

  4. #4
    Senior Member OpenGL Pro Ilian Dinev's Avatar
    Join Date
    Jan 2008
    Location
    Watford, UK
    Posts
    1,294

    Re: glVertexPointer, ivalid operation in gl 3.2 ?

    glVertexPointer was removed, not VBOs...

  5. #5
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,571

    Re: glVertexPointer, ivalid operation in gl 3.2 ?

    Quote Originally Posted by Ilian Dinev
    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.

  6. #6
    Junior Member Regular Contributor
    Join Date
    Sep 2008
    Posts
    139

    Re: glVertexPointer, ivalid operation in gl 3.2 ?

    Thanks,
    I got it. After reading the quick reference guide and a tutorial.
    I read this tutorial http://www.opengl.org/wiki/Tutorial:...C%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.

    Code :
    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..

    Code :
    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.getAttribLocation("in_Position"));
    glDisableVertexAttribArray(shader.getAttribLocation("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

  7. #7
    Junior Member Regular Contributor
    Join Date
    Sep 2008
    Posts
    139

    Re: glVertexPointer, ivalid operation in gl 3.2 ?

    Solved,
    I missed to set the offset for the components.

    regards,
    lobbel

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •