Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8166339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:49:49+00:00 2026-06-06T19:49:49+00:00

I had to convert some code (which deals with building a VBO of data

  • 0

I had to convert some code (which deals with building a VBO of data for the outlines of 2D shapes, i.e. they are not just triangle meshes, they can be an arbitrary length polygon outline) from using primitive restart to using glMultiDrawElements. I now realize glMultiDrawArrays is actually more appropriate for my application but that is not relevant to the question (indeed I would not have encountered this curious problem if I had been smarter and ported it to use glMultiDrawArrays instead).

I assembled two vectors to store the data for storing the requisite values:

struct E_MDEGBuffer {
    std::vector<GLvoid*> indices;
    std::vector<GLsizei> lengths;
};

Then what I did was for each polygon with N vertices push a single value to both indices and lengths, in indices I inserted (char*)NULL+index where index is the index in the IBO which corresponds to the first vertex of the polygon, and in lengths I place the integer number of vertices in that polygon.

The E_MDEGBuffer struct is used to pass values to glMultiDrawElements like so:

glMultiDrawElements(GL_TRIANGLE_FAN, mde.lengths.data(), GL_UNSIGNED_INT, (const GLvoid**)mde.indices.data(), mde.indices.size()); 

I test my program and the render is completely screwed up.

Eventually I fiddle around a bit with some hard-coded values passed into glMultiDrawElements and I discover that my indices values were off by a factor of 4.

Consider as an example the first polygon has 3 vertices and the second polygon has 5 vertices.

To get correct results my indices vector contains [0,0xc] and lengths contains [3,5].

Why should indices not be [0,0x3]?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T19:49:51+00:00Added an answer on June 6, 2026 at 7:49 pm

    The offset provided to the OpenGL buffer functions (such as glVertexAttribPointer) is always a data size offset, rather than an index.

    The number passed in must be of GLvoid* (or in this case GLvoid**) type but having the value that is the byte offset. It helps to think about how it could ever possibly be justified to have that pointer type for this parameter, and it being a byte-offset value goes (a short way) toward that.

    I don’t know what it was at first that made me think it was just the index offset but that is wrong and I paid the price.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert some code which was based on DX9 under .NET1.1 to
Im trying to convert some Delphi code to c# and I've come across a
I had to build a C program which convert's infix notation into postfix notation
I was working on some code recently and came across a method that had
I had some code that worked fine removing punctuation/numbers using regular expressions in python,
I had written a program in Python 3, but now want to convert it
I had a debate about macros and their readability. I think that in some
i am used to code in ASM and had the need to switch to
In SharePoint 2003 and 2007, there was a table called AllLists which had a
In some code I have converted to SSE I preform some ray tracing, tracing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.