# OpenGL confused with vbos

This topic is 4098 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

i'm a little confused with vbos i thought that the indices should be something like {1,2,3} for triangles. But in openGL superbible 4 in their thunderbird example they use 9 ints to define a triangle. Something like {1,0,2 ,3 ,1 ,5, 3 , 1 ,5}. Can someone point me to a good example of using VBO's or explain whats the deal with them? EDIT: looking more at the data from the source code that came with the book i can see that the first 3 ints are 3 vertexes the next 3 are normals and the next are 3 texvoords. am i right on this? And if so is there any way to tell OpenGL how the data is organized

##### Share on other sites
Unless you want to have seperate index buffers for every single triangle (and you don't), 9 indices simply mean 3 triangles (or a triangle strip/fan of 7 triangles).

##### Share on other sites
Quote:
 Original post by TriencoUnless you want to have seperate index buffers for every single triangle (and you don't), 9 indices simply mean 3 triangles (or a triangle strip/fan of 7 triangles).

The first 3 numbers all always smaller than the number of vertices the next 3 smaller than the number of normals and the last 3 smaller than the number of texcoords. So the array it's arranged as [ V V V N N N T T T]. But wouldn't 3 triangles be arranged as [ V N T V N T V N T] where V=vertex N=normal and T=texcoords

##### Share on other sites
If I understand you correctly I should probably point out that you can NOT use different indices for different vertex attribues (position, normal, texcoord). It will always use the same index for ALL of these.

You tell OpenGL how the data is organized by using the different glXPointer calls with appropriate strides and offsets. But for your index buffer it's irrelevant, as strictly speaking a vertex is always the entirety of it's attributes and not just the position.

##### Share on other sites
let's see if i got it right.
if i'm right this should be a cube in VBOs:
GLfloat vertex[]={ -2.0f, 2.0f, 2.0f, // 0                     2.0f, 2.0f, 2.0f, // 1                    2.0f, -2.0f, 2.0f,// 2                    -2.0f, -2.0f, 2.0f,// 3                    -2.0f, 2.0f, -2.0f,// 4                      2.0f, 2.0f, -2.0f,// 5                    2.0f, -2.0f, -2.0f,// 6                    -2.0f, -2.0f, -2.0f };// 7GLubyte index[]={ 0, 1, 2, 3,	// Front Face                  4, 5, 1, 0,	// Top Face                  3, 2, 6, 7,	// Bottom Face                  5, 4, 7, 6,	// Back Face	          1, 5, 6, 2,	// Right Face	          4, 0, 3, 7 };	// Left Facevoid setupVBOs(){     glGenBuffers(2,buffID);     glBindBuffer(GL_ARRAY_BUFFER,buffID[0]);glBufferData(GL_ARRAY_BUFFER,sizeof(float)*3*numVertex,vertex,GL_STATIC_DRAW);     glBindBuffer(GL_ELEMENT_ARRAY_BUFFER,buffID[1]);glBufferData(GL_ELEMENT_ARRAY_BUFFER,sizeof(GLubyte)*numIndex,index,GL_STATIC_DRAW);  }void Draw(){    glEnableClientState(GL_VERTEX_ARRAY);    {	glBindBuffer(GL_ARRAY_BUFFER, buffID[0]);	glVertexPointer(3, GL_FLOAT,0, 0);        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, buffID[1]);	glDrawElements(GL_TRIANGLES, numIndex, GL_UNSIGNED_BYTE, 0);	}    glDisableClientState(GL_VERTEX_ARRAY);}

1. 1
2. 2
Rutin
21
3. 3
4. 4
5. 5

• 13
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633736
• Total Posts
3013601
×