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 6976571
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:30:51+00:00 2026-05-27T17:30:51+00:00

i’m having this issue with VBO’s that I don’t really understand. My problem is

  • 0

i’m having this issue with VBO’s that I don’t really understand. My problem is solved by accidentally changing the last parameter in the glVertexAttribPointer method call. So, I’m looking for an answer as to WHY this is suddenly working or why my previous code isn’t working anymore. (just to get a better understanding on opengl)

Struct:

typedef struct 
{
    float position[3];
    float color[4];
} Vertex;

Without VBOs:

// Get pointers to the data
GLsizei stride = sizeof(Vertex);
const GLvoid *pCoords = &squareVertices[0].position[0];
const GLvoid *pColors = &squareVertices[0].color[0];

// Setup pointers to positions and colors
glVertexAttribPointer(positionSlot, 3, GL_FLOAT, GL_FALSE, stride, pCoords);
glVertexAttribPointer(colorSlot, 4, GL_FLOAT, GL_FALSE, stride, pColors);

// Draw
glDrawArrays(GL_TRIANGLES, 0, sizeof(squareVertices) / sizeof(Vertex));

With VBOs (this gives me an EXC_BAD_ACCESS)

// Stide
GLsizei stride = sizeof(Vertex);

// Setup pointers to positions and colors
glVertexAttribPointer(positionSlot, 3, GL_FLOAT, GL_FALSE, stride, 0);
glVertexAttribPointer(colorSlot, 4, GL_FLOAT, GL_FALSE, stride, (GLvoid*) (sizeof(float) * 3));

// Draw
glDrawElements(GL_TRIANGLES, sizeof(squareIndices) / sizeof(squareIndices[0]), GL_UNSIGNED_BYTE, 0);

So, the only thing that actually differs is the glVertexAttribPointer call which had a pointer to the data and now has fixed numbers. Can anyone elaborate on this? Thanks in advance.

  • 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-05-27T17:30:51+00:00Added an answer on May 27, 2026 at 5:30 pm

    When a VBO is active, the last parameter to glVertexAttribPointer is not really a pointer, but the offset inside the vertex buffer object type-cast to a pointer. That’s how VBOs work: the data has been copied to some memory managed by the graphics driver, you don’t know its address. In fact, it might not even have a normal address when it’s stored somewhere on your graphics card.

    The rest is cheating around the C/C++ type system. The type system is nowhere near smart enough to understand that glVertexAttribPointer‘s last argument should be a pointer-sized integer offset when a VBO is active, and a pointer otherwise. So to the C++ compiler, this has to look like a pointer all the time, because that is how glVertexAttribPointer (or rather, it’s predecessors glVertexPointer and friends) where defined originally. When it is really just a number, we just use a type cast to cheat the compiler.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am currently running into a problem where an element is coming back from

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.