PDA

View Full Version : Problem with VBO



cookiesoft
04-21-2013, 04:55 AM
Hey everybody,
I've got a problem with the VBO in C++ (und Mac OS x Lion). First of all thats my code:
Init:


float vertexBuffer[8] = {
0.0F, 0.0F,
0.0F, h,
w, h,
0.0F, h
};
unsigned int vertexIndices[4] = {
0, 1, 2, 3
};

glGenBuffers(2, bufferId);
glBindBuffer(GL_ARRAY_BUFFER, bufferId[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId[1]);
glBufferData(GL_ARRAY_BUFFER, sizeof(vertexBuffer), vertexBuffer, GL_STATIC_DRAW);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(vertexIndices), vertexIndices, GL_STATIC_DRAW);

And render:


glBindBuffer(GL_ARRAY_BUFFER, bufferId[0]);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferId[1]);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(2, GL_FLOAT, 8*sizeof(float), 0);

glColor3f(1.0f, 1.0f, 1.0f);
glDrawElements(GL_QUADS, 2, GL_UNSIGNED_INT, 0);

glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

Now the problem is it displays nothing. No error or sth like that. Can somebody please help me? Thanks
Greedings,
CookieSoft

arekkusu
04-21-2013, 10:41 AM
You've specified a stride between vertices of 8*sizeof(float) = 32 bytes. But your vertex data is tightly packed and actually has a stride of 2*sizeof(float) = 8 bytes.

You've also drawn a QUAD with only two vertices, which is an incomplete primitive. You need four vertices per quad.

cookiesoft
04-21-2013, 10:46 AM
thx for the answer! But i tried it and it displays nothing... (By the way iam using glut if it helps)

cookiesoft
04-22-2013, 10:42 AM
ok i have the error the index array is wrong srry for the noob error ;) vertexIndices must be 0, 2, 4, 6