Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: glDrawElements - multiple calls, one index array?

  1. #1
    Member Newbie
    Join Date
    Nov 2011
    Location
    Fairborn, OH
    Posts
    31

    glDrawElements - multiple calls, one index array?

    I have an array of indexes stored with VBO's and I'm currently calling glDrawElements like so:

    Code :
    glDrawElements(GL_LINES, m_indices.size(), GL_UNSIGNED_INT, 0);

    Is it possible to make an additional call to glDrawElements to render only a single point from my list of existing indices? I've tried doing it and keep getting an access violation. Here's the method I'm trying to use (with the existing line as well):

    Code :
    glDrawElements(GL_LINES, m_indices.size(), GL_UNSIGNED_INT, 0);
    glDrawElements(GL_POINTS, 1, GL_UNSIGNED_INT, &m_indices[CurrCellIndex]);

    Where CurrCellIndex is the index for the vertex that I want a point rendered. What am I doing wrong?

  2. #2
    Senior Member Regular Contributor imported_tksuoran's Avatar
    Join Date
    Mar 2008
    Location
    Cambridge, UK
    Posts
    223

    Re: glDrawElements - multiple calls, one index array?

    Your last arg is wrong. When using VBO, it is an offset, but you are passing a whole pointer. Try something like CurrCellIndex * sizeof(unsigned int).

  3. #3
    Member Newbie
    Join Date
    Nov 2011
    Location
    Fairborn, OH
    Posts
    31

    Re: glDrawElements - multiple calls, one index array?

    I don't think I'm following you. does that replace the entire last argument or is that supposed to be &m_indices[CurrCellIndex * sizeof(unsigned int)]?

    the book I have says that the last argument is supposed to be a pointer to the start of the array. Should my second argument be the CurrCellIndex?

  4. #4
    Member Newbie
    Join Date
    Nov 2011
    Location
    Fairborn, OH
    Posts
    31

    Re: glDrawElements - multiple calls, one index array?

    I've tried both glDrawElements and glDrawRangeElements and no matter what I do I can't get it to draw just one point from one index of my existing indices.

    if I do:

    Code :
    glDrawElements(GL_LINES, m_indices.size(), GL_UNSIGNED_INT, 0);
    glDrawElements(GL_POINTS, 0, GL_UNSIGNED_INT, 0);
    I get all the points drawn with all the lines. (it's probably drawing all the points twice because my indices are set up for lines (0,1,1,2,etc.))

    if I do:

    Code :
    glDrawElements(GL_LINES, m_indices.size(), GL_UNSIGNED_INT, 0);
    glDrawRangeElements(GL_POINTS, CurrCellIndex, CurrCellIndex, 1, GL_UNSIGNED_INT, 0);
    I get the first point drawn. It only draws the point represented by the first index, ignoring the start and end values I specify via CurrCellIndex.

    Interestingly enough, if I put anything other than 0 in my last argument (such as &m_indices[0], or &m_indices[CurrCellIndex]) I get the access violation.

  5. #5
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: glDrawElements - multiple calls, one index array?

    the last argument is supposed to be a pointer to the start of the array
    yes and no. It is a pointer if you use Vertex Arrays (that is if your data is stored in client memory). You are using VBOs which means your data is stored in server memory. The draw functions are overloaded for both uses and depending on what you use (Vertex Arrays vs. VBO) the last argument is either a proper pointer or an offset into the VBO.

    Should my second argument be the CurrCellIndex?
    no, because you only want to use one index, not CurrCellIndex many.

  6. #6
    Member Newbie
    Join Date
    Nov 2011
    Location
    Fairborn, OH
    Posts
    31

    Re: glDrawElements - multiple calls, one index array?

    How do I specify an offset then other than 0? I want my offset to be CurrCellIndex, but its not accepting that.

  7. #7
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: glDrawElements - multiple calls, one index array?

    Actually the above is not entirely correct. It does not matter whether your vertex data is in client or server memory, but where your index data is.
    So, if you have uploaded your indices to server memory (using something like glBufferData(GL_ELEMENT_ARRAY_BUFFER, ...) ) and have a buffer bound to GL_ELEMENT_ARRAY_BUFFER when making your draw calls, the "indices" pointers are not really pointers, but offsets into the index buffer.

  8. #8
    Newbie Frequent Contributor
    Join Date
    Mar 2016
    Posts
    896

    Re: glDrawElements - multiple calls, one index array?

    As tksuoran said, it should be CurrCellIndex * sizeof(unsigned int):

    Code :
    glDrawElements(GL_LINES, m_indices.size(), GL_UNSIGNED_INT, 0);
    glDrawElements(GL_POINTS, 1, GL_UNSIGNED_INT, CurrCellIndex * sizeof(unsigned int));

    Does that not work? Is CurrCellIndex < m_indices.size()?

  9. #9
    Member Newbie
    Join Date
    Nov 2011
    Location
    Fairborn, OH
    Posts
    31

    Re: glDrawElements - multiple calls, one index array?

    I get an error stating that parameter 4 cannot ve converted from unsigned int to 'const GLvoid'

    I tried putting it in parentheses also. CurrCellIndex is < m_indices.size()

  10. #10
    Senior Member Regular Contributor imported_tksuoran's Avatar
    Join Date
    Mar 2008
    Location
    Cambridge, UK
    Posts
    223

    Re: glDrawElements - multiple calls, one index array?

    You need to cast it. See BUFFER_OFFSET macro on http://www.opengl.org/wiki/Vertex_Buffer_Object

Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 6
    Last Post: 09-04-2012, 10:00 AM
  2. glDrawElements does not uses per index uv/normal!
    By standy in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 02-07-2011, 04:15 AM
  3. Normals index with glDrawElements !
    By golgoth13 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-08-2006, 12:41 AM
  4. glDrawElements index bias parameter (like in d3d9)
    By Nitrogenycs in forum OpenGL: General
    Replies: 0
    Last Post: 12-21-2004, 09:08 AM
  5. vertexdata per index in glDrawElements
    By jabe in forum OpenGL: General
    Replies: 2
    Last Post: 02-03-2001, 03:08 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean