   VBO issues - please help.
  Well, till today i finally managed how to draw all my objects with a single VBO: glGenBuffers( 1, &currentMesh.m_nVBOVertices );glBindBuffer( GL_ARRAY_BUFFER, currentMesh.m_nVBOVertices );glBufferData( GL_ARRAY_BUFFER, sizeof(XYNVector3)*currentMesh.numOfVerts,m_pVertices, GL_STATIC_DRAW );glBindBuffer( GL_ARRAY_BUFFER, 0 ); ...SHADERS.enable(1);glActiveTextureARB(GL_TEXTURE1_ARB);glEnable(GL_TEXTURE_2D);glBindBufferARB( GL_ARRAY_BUFFER_ARB,m_Model.pObject[0].m_nVBOVertices  );glEnableClientState(GL_TEXTURE_COORD_ARRAY);glTexCoordPointer(2, GL_FLOAT,sizeof(XYNVector3),(char *)OFFSETT);glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer( 3, GL_FLOAT,0,(char *)0);glDrawElements(GL_TRIANGLES, (m_Model.pObject[0].numOfFaces)*3, GL_UNSIGNED_INT,m_Model.pObject[0].m_pIndices);glClientActiveTexture(GL_TEXTURE0_ARB);glDisableClientState(GL_TEXTURE_COORD_ARRAY);glBindBufferARB( GL_ARRAY_BUFFER_ARB, 0);SHADERS.disable(1);And this works great,however, i would like to add texture uv to my rendering.XYNVector3 structure looks as follows:struct XYNVector3{public:// A default constructorXYNVector3() { }// The cross product between two XYNVector3 vectorsXYNVector3 Cross(XYNVector3 vVector2){XYNVector3 vNormal;// Calculate the cross product with the non-commutative equationvNormal.x = ((y * vVector2.z) - (z * vVector2.y));vNormal.y = ((z * vVector2.x) - (x * vVector2.z));vNormal.z = ((x * vVector2.y) - (y * vVector2.x));// Return the cross productreturn vNormal; }// The dot product between two XYNVector3 vectorsGLfloat Dot(const XYNVector3& v) const{return ( (x * v.x) + (y * v.y) + (z * v.z) );}// This is our constructor that allows us to initialize our data upon creating an instanceXYNVector3(GLfloat X, GLfloat Y, GLfloat Z) { x = X; y = Y; z = Z;}// This is our operator overloaded addition/assignment for a XYNVector3XYNVector3& operator+=(const XYNVector3& v){// Add the vector to our current vectorx += v.x;y += v.y;z += v.z;// Return the changed vector backreturn *this;}// Here we overload the + operator so we can add vectors together XYNVector3 operator+(XYNVector3 vVector){// Return the added vectors result.return XYNVector3(vVector.x + x, vVector.y + y, vVector.z + z);}// Here we overload the - operator so we can subtract vectors XYNVector3 operator-(XYNVector3 vVector){// Return the subtracted vectors resultreturn XYNVector3(x - vVector.x, y - vVector.y, z - vVector.z);}// Here we overload the * operator so we can multiply by scalarsXYNVector3 operator*(GLfloat num){// Return the scaled vectorreturn XYNVector3(x * num, y * num, z * num);}// Here we overload the / operator so we can divide by a scalarXYNVector3 operator/(GLfloat num){// Return the scale vectorreturn XYNVector3(x / num, y / num, z / num);} GLfloat x, y, z;GLfloat texcoords[2]; };Do i have to generate another VBO to have it a go ?Or i should use my code above and do the 'offseting' stuff in the glTexCoordPointer?When should i choose between:GL_ELEMENT_ARRAY_BUFFER && GL_ARRAY_BUFFER ?[Edited by - razor1911 on May 29, 2010 4:57:26 PM]
  When i try to useGL_ELEMENT_ARRAY_BUFFER my model is all mashed up, verts are flying all over.Here is how i am generating the second VB and the new render,; glBindBuffer( GL_ARRAY_BUFFER,m_Model.pObject[0].m_nVBOVertices  );glBindBuffer( GL_ELEMENT_ARRAY_BUFFER,m_Model.pObject[0].m_nVBOIndices );  glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer( 3, GL_FLOAT,sizeof(XYNVector3),xBUFFER_OFFSET(0));  glDrawElements(GL_TRIANGLES, (m_Model.pObject[0].numOfFaces)*3, GL_UNSIGNED_INT,0);  glDisableClientState(GL_VERTEX_ARRAY);glDisableClientState(GL_ELEMENT_ARRAY_BUFFER);glBindBufferARB( GL_ARRAY_BUFFER, 0);glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0);  ... glBindBuffer( GL_ARRAY_BUFFER,m_Model.pObject[0].m_nVBOVertices  );glBindBuffer( GL_ELEMENT_ARRAY_BUFFER,m_Model.pObject[0].m_nVBOIndices );  glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer( 3, GL_FLOAT,sizeof(XYNVector3),xBUFFER_OFFSET(0));  glDrawElements(GL_TRIANGLES, (m_Model.pObject[0].numOfFaces)*3, GL_UNSIGNED_INT,0);  glDisableClientState(GL_VERTEX_ARRAY);glDisableClientState(GL_ELEMENT_ARRAY_BUFFER);glBindBufferARB( GL_ARRAY_BUFFER, 0);glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0); The previous render works great, all i am missing are the textures,what do i do wrong with the new one?Where is the trick..?   ;  GL_ELEMENT_ARRAY_BUFFER is for the index buffer, not for vertex data.Yes, you should include your UV data into the vertex struct, and offset the glTexCoordPointer.   ;  Please excuse, i haven't pasted the correct glGenBuffers to the second post, where i want to render using VBO and IBO:This is how i generate the VBO/IBO;//m_pIndices = GLuint*m_pIndices//pVerts= XYNVector3  *pVerts;//numIndices = int//numOfVerts = int glGenBuffers( 1, &currentMesh.m_nVBOVertices );glBindBuffer( GL_ARRAY_BUFFER, currentMesh.m_nVBOVertices );glBufferData( GL_ARRAY_BUFFER, sizeof(XYNVector3)*currentMesh.numOfVerts,currentMesh.pVerts, GL_STATIC_DRAW );glBindBuffer( GL_ARRAY_BUFFER, 0 );  glGenBuffers( 1, &currentMesh.m_nVBOIndices);glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, currentMesh.m_nVBOIndices );glBufferData( GL_ELEMENT_ARRAY_BUFFER, 3*sizeof(GLuint)*currentMesh.numIndices, currentMesh.m_pIndices, GL_STATIC_DRAW );glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, 0 ); and the render:; glBindBuffer( GL_ARRAY_BUFFER,m_Model.pObject[0].m_nVBOVertices  );glBindBuffer( GL_ELEMENT_ARRAY_BUFFER,m_Model.pObject[0].m_nVBOIndices );  glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer( 3, GL_FLOAT,sizeof(XYNVector3),xBUFFER_OFFSET(0));  glDrawElements(GL_TRIANGLES, (m_Model.pObject[0].numOfFaces)*3, GL_UNSIGNED_INT, 0);  glDisableClientState(GL_VERTEX_ARRAY);glDisableClientState(GL_ELEMENT_ARRAY_BUFFER);glBindBufferARB( GL_ARRAY_BUFFER, 0);glBindBufferARB( GL_ELEMENT_ARRAY_BUFFER_ARB, 0);  So as far as i understand it,to render an object by VBO with :texture coordinatesi need to useIBO and VBO i cannot use onlyVBOam i correct?Now when i render, i get my model mixed up, verts are flying all over the scene,why does the first render work fine ( having no textures ) and my second approach with IBO is bad.. ?What do i do wrong?   ;Quote:So as far as i understand it,to render an object by VBO with :texture coordinatesi need to useIBO and VBOi cannot use onlyVBOam i correct?No you are not correct, anything you can render with glDrawElements (indices) you can render just as well with glDrawArrays() (non-indexed). It is just a different way of specifying data.If your model looks wrong when you're using indices you've likely specified the wrong data somehow. If you want to use indices then try just rendering one or two triangles and see if you can get those right.   ;  My model renders perfectly when i render it : glBindBuffer( GL_ARRAY_BUFFER,m_Model.pObject[0].m_nVBOVertices  ); glEnableClientState(GL_VERTEX_ARRAY);glVertexPointer( 3, GL_FLOAT,0,(char *)0);glDrawElements(GL_TRIANGLES, (m_Model.pObject[0].numOfFaces)*3, GL_UNSIGNED_INT,m_Model.pObject[0].m_pIndices);glDisableClientState(GL_VERTEX_ARRAY);glBindBufferARB( GL_ARRAY_BUFFER, 0);AS you can see, i have disabled the IBO and it is renderer perfectly without textures.Now i need to add the texture to it,but when i do;glVertexPointer( 3, GL_FLOAT,sizeof(XYNVector3),(char *)0);//instead ofglVertexPointer( 3, GL_FLOAT,0,(char *)0);//model gets mixed up again during renderI need this stride as XYNVector3 is a structure holdingfloat x,y,z; //verticesfloat texcoordX;float texcoordY;what's going on?   ;  What exactly is wrong when you try to add the texture?Your glVertexPointer command looks correct, but maybe there is something else you are not doing. Did you try my advice to start simple, maybe with a textured quad?   