PDA

View Full Version : yet another VBO cuestion



juglarx
12-14-2007, 04:29 PM
hi guys! i try to rendenr a simple cube using VBO but when i render it i see a cube without a triangle in all the faces(just 1 triangle x face) here is the code that i use

for init
------8<----code----------8<-------------------------------------
unsigned int modelPointsBufferID;
GLfloat verticesCube[] = {100,100,100, -100,100,100, -100,-100,100, 100,-100,100, // v0-v1-v2-v3
100,100,100, 100,-100,100, 100,-100,-100, 100,100,-100, // v0-v3-v4-v5
100,100,100, 100,100,-100, -100,100,-100, -100,100,100, // v0-v5-v6-v1
-100,100,100, -100,100,-100, -100,-100,-100, -100,-100,100, // v1-v6-v7-v2
-100,-100,-100, 100,-100,-100, 100,-100,100, -100,-100,100, // v7-v4-v3-v2
100,-100,-100, -100,-100,-100, -100,100,-100, 100,100,-100}; // v4-v7-v6-v5


int allocationSize = sizeof(verticesCube);
glGenBuffersARB(1, &modelPointsBufferID);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, modelPointsBufferID);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(verticesCube), verticesCube, GL_STATIC_DRAW_ARB);

------8<----code----------8<-------------------------------------


And when i draw

------8<----Render code--------8<-------------------------------

glBindBufferARB(GL_ARRAY_BUFFER_ARB, modelPointsBufferID);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, 0);

glDrawArrays(GL_TRIANGLES, 0, 24);

glDisableClientState(GL_VERTEX_ARRAY);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
------8<----Render code--------8<-------------------------------

i can't figure out what happend thanks in advance to any help!!

sharp_pixel
12-14-2007, 05:45 PM
Hi

Try glDrawArrays(GL_QUADS, 0, 24); instead of glDrawArrays(GL_TRIANGLES, 0, 24);

juglarx
12-14-2007, 11:14 PM
its work well now thanks sharp_pixel, now i store it in a std::vector<float> and didn't work again any trick of using std::vector<float> and VBO ??

Jan
12-15-2007, 04:27 AM
std::vector<float> data;

data.push_back (....);
...

glBufferDataARB(GL_ARRAY_BUFFER_ARB, data.size (), &data[0], GL_STATIC_DRAW_ARB);

Should work the same as with standard arrays.

Jan.

martinsm
12-15-2007, 08:32 AM
You should pass size of data in bytes for second argument:

glBufferDataARB(GL_ARRAY_BUFFER_ARB, data.size() * sizeof(float), &data[0], GL_STATIC_DRAW_ARB);

juglarx
12-15-2007, 09:17 PM
thanks thtat help me a lot