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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T11:02:54+00:00 2026-05-25T11:02:54+00:00

I have following struct to store my vertex data. struct Rz3DContourNode { float x;

  • 0

I have following struct to store my vertex data.

struct Rz3DContourNode {
  float x; //pos x
  float y;   //pos y
  float z;  //pos z
  float nx;  //normal x
  float ny;  //normal y
  float nz;  //normal z
};

I store list of vertices in STL vector as follows :

std::vector < Rz3DContourNode >  nodes;

When I try to use this as as vertex-array in OPEGL ,in does not render incorrectly.

glVertexPointer(3, GL_FLOAT, 12, &nodes[0]);
glDrawArrays(GL_POINTS,0,nodes.size());

So, I tried to confirm the values using pointer arithmetic (assuming thats the way OPENGL handle data) as follows:

float *ptr=(float*) &nodes[0];

for(int i=0;i<nodes.size();i++)
{

   Rz3DContourNode confirmNode=nodes[i];  

  float x=*ptr;
    ptr++;

  float y=*ptr;
    ptr++;

  float z=*ptr;
     ptr++;


  //Confirm values !!! Do not equal ??
  qDebug("x=%4.2f  y=%4.2f z=%4.2f  | nx=%4.2f ny=%4.2f nz=%4.2f
        ",confirmNode.x,confirmNode.y,confirmNode.z,x,y,z);



  //Skip normal positions
  ptr++;
  ptr++;
  ptr++;

}

The values does not equal if I directly access values from the struct.

Does this means struct does not save the values contiguously ?

[EDIT] I Just noticed that using sizeof() instead of 12 fix the problem as follows:

glVertexPointer(3, GL_FLOAT, sizeof(Rz3DContourNode), &nodes[0]);

But still I am confused why my hack didnt traverse correctly in memory?(why qDebug doesnt print identical values ?)

  • 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-25T11:02:55+00:00Added an answer on May 25, 2026 at 11:02 am
    sizeof(Rz3DContourNode) == 6*4 = 24 bytes ... not 12!
    

    The stride is the # of bytes between the start of each vertex, not the padding. Although 0 is a special value that indicates tightly packed data.

    So, if you’re using 3 floats as vertex data, there’s no difference between a stride of 0 and 12 (because 3 floats are 12 bytes). In your case, your struct is 24 bytes, so you should put that.

    This convention (stride = step size, not padding) allows the simple use of sizeof, so you ended up doing the the right thing intuitively. That’s good API design for you. 🙂

    See glVertexPointer docs:

    stride

    Specifies the byte offset between consecutive vertices. If stride
    is 0, the vertices are understood to be tightly packed in the array.
    The initial value is 0.

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

Sidebar

Related Questions

I have the following construction: typedef struct bucket { char *key; ENTRY *data; struct
Suppose I have the following: typedef struct { int itemSize; int count; void *list;
I have the following struct in C++: #define MAXCHARS 15 typedef struct { char
I have the following use case, a struct with some boolean and int variables
I have some generic types, like the following: public struct Tuple<T1, T2> { ...
Hi I have the following union which is part of a larger struct and
I have a function that takes a struct, and I'm trying to store its
I have an array of constant data like following: enum Language {GERMAN=LANG_DE, ENGLISH=LANG_EN, ...};
What I mean is, say I have a struct to represent some data and
i have the following struct: struct Message { Agent *_agent; double _val; }; and

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.