Jump to content
  • Advertisement
Sign in to follow this  
DumitruSorin

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by Trienco
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).


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 this post


Link to post
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 this post


Link to post
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 };// 7
GLubyte 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 Face

void 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);

}



Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!