PDA

View Full Version : VBO following Objects are the same



cookiesoft
05-30-2013, 06:34 AM
Hey everybody,
I've got a VBO class where I create a vbo with texture and stuff.
This is how it looks like


GLfloat vertexBuffer[8] = {
0.0F, 0.0F,
0.0F, height,
width, height,
width, 0.0F
};

GLfloat textureBuffer[8] = {
texturePositionX, texturePositionY,
texturePositionX, texturePositionY + textureHeight,
texturePositionX + textureWidth, texturePositionY + textureHeight,
texturePositionX + textureWidth, texturePositionY
};

GLubyte indexBuffer[4] = {
0, 2, 4, 6
};
glGenBuffers(1, &vbIdentifier);
glBindBuffer(GL_ARRAY_BUFFER, vbIdentifier);
glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, 8 * sizeof(GLfloat), vertexBuffer);
glVertexPointer(2, GL_FLOAT, sizeof(GLfloat), 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);

glGenBuffers(1, &tbIdentifier);
glBindBuffer(GL_ARRAY_BUFFER, tbIdentifier);
glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), NULL, GL_STATIC_DRAW);
glBufferSubData(GL_ARRAY_BUFFER, 0, 8 * sizeof(GLfloat), textureBuffer);
glTexCoordPointer(2, GL_FLOAT, sizeof(GLfloat), 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);

glGenBuffers(1, &ivbIdentifier);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ivbIdentifier);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 4 * sizeof(GLubyte), indexBuffer, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

(I program under mac osx)
Thats how i initialize my VBO. Now when I create two different VBOs the first VBO is the same as the second VBO. Why does this happen?
Thx for help :)!
Greetings Cookiesoft

noopnoop
05-30-2013, 07:02 AM
what do you mean by the same?
the ids? or the data?

If you mean the data, you need to show the rendering of the buffers, since gl*Pointer is client state and you need to activate those pointer during rendering, unless you use vertex array objects...

See

http://www.opengl.org/registry/specs/ARB/vertex_buffer_object.txt

at the very end of the document where the examples are.

I mean, the gl*Pointer calls are meaningless in this context, to my knowledge. You need to use those pointers if you want to render.
You also need to activate the client state for those pointers. So every time you render you need to set those pointer. If you like to give VAO a chance, you only need to activate those pointers once for each VAO.

http://www.opengl.org/registry/specs/ARB/vertex_array_object.txt

cookiesoft
05-30-2013, 07:51 AM
I mean the data is the same(the width and height and texcoords stay the same). And I activated the pointer during rendering:

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glBindBuffer(GL_ARRAY_BUFFER, vbIdentifier);
glBindBuffer(GL_ARRAY_BUFFER, tbIdentifier);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ivbIdentifier);
glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

glDrawElements(GL_QUADS, 8, GL_UNSIGNED_BYTE, 0);

glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); So I don't think that this is the problem.

cookiesoft
05-30-2013, 09:08 AM
Oh srry now I got it! I've put the Pointer line in the render code not in the init code! Thanks!

noopnoop
05-30-2013, 09:35 AM
I've put the Pointer line in the render code not in the init code!

I bet you mean the other way around... ;) Glad it helped.