   VBO struct offsets
  I'm trying to display a random generated heightfield using a VBO, but I think I  got the offsets to the struct im trying to upload wrong. It draws nothing at all. My system should support drawing VBO's because I followed this tutorial(http://sdickinson.com/wordpress/?p=122) and the sample code works perfectly. The heightmap data is generated as follows:mHEIGHTDATA::mHEIGHTDATA():size(TERRAIN_DEFAULT_SIZE)// default size = 256 and the map is square {heightmap.reserve(size*size);// 256 * 256 tiles total, heightmap is a vector<mGEOMETRY_TERRAIN> index.reserve(size*size*6);// 6 indices per tile, index is a vector<GLuint>for(unsigned int x = 0; x < size; x++){for(unsigned int y = 0; y < size; y++){  //location 3(random height),uv coords2, normal 3color 4(red),  padding 16mGEOMETRY_TERRAIN node = {float(x), randFloat(), float(y), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};heightmap.push_back( node );if((x < size) && (y < size)){// make sure not to generate 256 + 1 indices for rows and columnsindex.push_back(y+ ( x * size));index.push_back(y+ ((x + 1) * size) );index.push_back(y+1 + ((x + 1) * size) );index.push_back(y+1 + ((x + 1) * size) );index.push_back(y+1 + ( x * size));index.push_back(y+ ( x * size));}}}}I've dumped the indices to a file to check them and they seem OK, i've also made a function using the old glBegin/glEnd and this displays the heightmap correctly. I think the data is OK. For the gl***Pointer calls I use a function that returns the offset of a member in a struct (offsetof, stddef.h)this is the struct Im trying to upload: (aligned to a multiple of 32)struct mGEOMETRY_TERRAIN{float location[3];float tex[2];float normal[3];float color[4];char padding[16];};this is the code I use to initialize the VBO and draw it. initVBO is called right before glutMainLoop and drawVBO is called in my drawing callback ofcoursevoid getOffsets(){glTexCoordPointer(2,GL_FLOAT, sizeof(mGEOMETRY_TERRAIN), (GLvoid *) offsetof(mGEOMETRY_TERRAIN, tex));glNormalPointer(GL_FLOAT, sizeof(mGEOMETRY_TERRAIN), (GLvoid *) offsetof(mGEOMETRY_TERRAIN, normal));glColorPointer(   4,GL_FLOAT, sizeof(mGEOMETRY_TERRAIN), (GLvoid *) offsetof(mGEOMETRY_TERRAIN, color));// call the vertexpointer last for performance reasons (OpenGL redbook)glVertexPointer(  3,GL_FLOAT, sizeof(mGEOMETRY_TERRAIN), (GLvoid *) offsetof(mGEOMETRY_TERRAIN, location));}void mTERRAIN::initVBO(){//class mTERRAIN has one mHEIGHTDATA member: heightdataglGenBuffers(1, &vertexVBOID);glBindBuffer(GL_ARRAY_BUFFER, vertexVBOID); glBufferData(GL_ARRAY_BUFFER, sizeof(mGEOMETRY_TERRAIN) * heightdata.size * heightdata.size, NULL, GL_STATIC_DRAW);glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(mGEOMETRY_TERRAIN) * heightdata.size * heightdata.size, &heightdata.heightmap[0]);getOffsets();glGenBuffers(1, &indexVBOID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, heightdata.size * sizeof(GLuint), &heightdata.index[0], GL_STATIC_DRAW);}void mTERRAIN::drawVBO(){glBindBuffer(GL_ARRAY_BUFFER, vertexVBOID);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID);glEnableClientState(GL_TEXTURE_COORD_ARRAY);glEnableClientState(GL_COLOR_ARRAY);glEnableClientState(GL_NORMAL_ARRAY);glEnableClientState(GL_VERTEX_ARRAY);getOffsets();glDrawElements(GL_TRIANGLES, heightdata.size, GL_UNSIGNED_BYTE, (GLvoid *) offsetof(mGEOMETRY_TERRAIN, location[0]));glDisableClientState(GL_TEXTURE_COORD_ARRAY);glDisableClientState(GL_COLOR_ARRAY);glDisableClientState(GL_NORMAL_ARRAY);glDisableClientState(GL_VERTEX_ARRAY);}using glut 20600, glew 1.5.4 and GL_VERSION = 2.1.8664   
  does it work if you do the offsets yourself instead of using offsetof? Did it work when(if) you tried it without vbos?   ;Quote:Original post by Nanohadoes it work if you do the offsets yourself instead of using offsetof? Did it work when(if) you tried it without vbos?setting them manually didnt work (i made sure to use the correct size with sizeof(float)) ie:glTexCoordPointer(2, GL_FLOAT, sizeof(mGEOMETRY_TERRAIN), 3*sizeof(float));since the float tex[2] comes after float location[3]the drawing works fine using the (deprecated) glBegin(GL_TRIANGLES)/glEnd() static functions but it is very slow on the 256*256*2 triangles heightfield. I've made a hotkey to switch between VBO and static rendering   ;  glDrawElements(GL_TRIANGLES, heightdata.size, GL_UNSIGNED_BYTE, (GLvoid *) offsetof(mGEOMETRY_TERRAIN, location[0]));There you are drawing triangles, your passing the n umber of indices in to be heightdata.size which I suspect is your number of points and not your number of indices. Maybe a similar problem when your setting up the element array. The last parameter should be 0 (which it probably is looking at your struct) unless your using multiple index buffers.Also, what are the values of tex, normal, color and location in your getOffsets function. Is offsetof returning expected values?   ;  'size' is the size of one side of the square heightmap. The number of indices should be size*size*6 (2 triangles 3 vertece)thats it! I've set the sizes wrong. I've changed it and its drawing now but I think I made an off-by-one error somewhere as its the connecting the last triangles drawn to the originhttp://img36.imageshack.us/f/img36/758/firstpatch.jpg(offsets set manually)void getOffsets(){glTexCoordPointer(2,GL_FLOAT, sizeof(mGEOMETRY_TERRAIN), (GLvoid *)(3*sizeof(float)));glNormalPointer(GL_FLOAT, sizeof(mGEOMETRY_TERRAIN), (GLvoid *)(5*sizeof(float)));glColorPointer(   4,GL_FLOAT, sizeof(mGEOMETRY_TERRAIN), (GLvoid *)(8*sizeof(float)));// call the vertexpointer last for performance reasons (OpenGL redbook)glVertexPointer(  3,GL_FLOAT, sizeof(mGEOMETRY_TERRAIN), (GLvoid *)(0*sizeof(float)));}void mTERRAIN::initVBO(){//class mTERRAIN has one mHEIGHTDATA member: heightdataglGenBuffers(1, &vertexVBOID);glBindBuffer(GL_ARRAY_BUFFER, vertexVBOID); glBufferData(GL_ARRAY_BUFFER, sizeof(mGEOMETRY_TERRAIN) * heightdata.size * heightdata.size, NULL, GL_STATIC_DRAW);glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(mGEOMETRY_TERRAIN) * heightdata.size * heightdata.size, &heightdata.heightmap[0]);getOffsets();glGenBuffers(1, &indexVBOID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, heightdata.size * heightdata.size * 6 * sizeof(GLuint), &heightdata.index[0], GL_STATIC_DRAW);}void mTERRAIN::drawVBO(){glBindBuffer(GL_ARRAY_BUFFER, vertexVBOID);glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexVBOID);glEnableClientState(GL_TEXTURE_COORD_ARRAY);glEnableClientState(GL_COLOR_ARRAY);glEnableClientState(GL_NORMAL_ARRAY);glEnableClientState(GL_VERTEX_ARRAY);getOffsets();glDrawElements(GL_TRIANGLES, heightdata.size * heightdata.size * 6, GL_UNSIGNED_INT, (GLvoid *)(0*sizeof(float)));glDisableClientState(GL_TEXTURE_COORD_ARRAY);glDisableClientState(GL_COLOR_ARRAY);glDisableClientState(GL_NORMAL_ARRAY);glDisableClientState(GL_VERTEX_ARRAY);}