init() {
glGenBuffersARB(1, &vbo);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
glBufferDataARB(GL_ARRAY_BUFFER_ARB, sizeof(float)*48, NULL, GL_STATIC_DRAW_ARB);
data=(float *)glMapBufferARB(GL_ARRAY_BUFFER_ARB, GL_WRITE_ONLY_ARB);
indices[0] = 0;
indices[1] = 1;
indices[2] = 2;
indices[3] = 3;
indices[4] = 4;
indices[5] = 5;
data[0] = -10.0000; // vertex x
data[1] = 20.0000; // vertex y
data[2] = 10.0000; // vertex z
data[3] = 0.000000; // texture s coord
data[4] = 1.00000; // texture t coord
data[5] = 0.000000; // normal x
data[6] = 0.000000; // normal y
data[7] = 1.00000; // normal z
data[8] = -10.0000;
data[9] = 0.000000;
data[10] = 10.0000;
data[11] = 0.000000;
data[12] = 0.000000;
data[13] = 0.000000;
data[14] = 0.000000;
data[15] = 1.00000;
data[16] = 10.0000;
data[17] = 20.0000;
data[18] = 10.0000;
data[19] = 0.000000;
data[20] = 0.000000;
data[21] = 0.000000;
data[22] = 0.000000;
data[23] = 1.00000;
data[24] = -10.0000;
data[25] = 0.000000;
data[26] = 10.0000;
data[27] = 0.000000;
data[28] = 0.000000;
data[29] = 0.000000;
data[30] = 0.000000;
data[31] = 1.00000;
data[32] = 10.0000;
data[33] = 0.000000;
data[34] = 10.0000;
data[35] = 0.000000;
data[36] = 0.000000;
data[37] = 0.000000;
data[38] = 0.000000;
data[39] = 1.00000;
data[40] = 10.0000;
data[41] = 20.0000;
data[42] = 10.0000;
data[43] = 0.000000;
data[44] = 0.000000;
data[45] = 0.000000;
data[46] = 0.000000;
data[47] = 1.00000;
}
drawScene() {
glBindTexture(GL_TEXTURE_2D, texture_id);
glBindBufferARB(GL_ARRAY_BUFFER_ARB, vbo);
// Stride is number of variant compoents per vertex
// in bytes, so multiply by the size of float, same for the offset
// Vertex positions are at offset 0
glVertexPointer(3, GL_FLOAT, sizeof(float)*8, BUFFER_OFFSET(0));
glEnableClientState(GL_VERTEX_ARRAY);
// Texture coords are at offset 3 (0 + 3vertex.xyz)
glTexCoordPointer(2, GL_FLOAT, sizeof(float)*8, BUFFER_OFFSET(sizeof(float)*3));
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
// Normals are at offset 5 (0 + 3vertex.xyz + 2texcoord.xy)
glNormalPointer(GL_FLOAT, sizeof(float)*8, BUFFER_OFFSET(sizeof(float)*5));
glEnableClientState(GL_NORMAL_ARRAY);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, indices);
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
}
Thanks,
Nitzan
ARB VBO question
I am trying to implement VBO and I wrote the following test code to, well, test it out. But it doenst seem to work. Can anyone tell me what I am doing wrong / missing ?
Shouldn''t you be unmapping the map before rendering? Maybe you missed that out of the post. Other than that it looks ok (presuming the index array is ok and supported by your card).
Whops, thanks!
I added the unmap and now I see my box on the screen.
Unfortunately the lighting and texture mapping is screwed up, but at least I can see something on the screen now so I can mess around with it.
Thanks!
Nitzan
I added the unmap and now I see my box on the screen.
Unfortunately the lighting and texture mapping is screwed up, but at least I can see something on the screen now so I can mess around with it.
Thanks!
Nitzan
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement