So, I tried to teach myself how to use VBOs to improve the performance of my OpenGL project and learn more complex things than rendering a fixed function. But I did not find much suitable textbook; the best of which I have found so far Songho tutorials and material in OpenGL.org , but I do not seem to know any background knowledge to fully understand what is happening, although I can’t say exactly what I don’t get save the use of several parameters.
In any case, I forged ahead and came up with some cannibalized code that, at least, does not break, but leads to unusual results. What I want to visualize is (displayed using a fixed function, it should be brown and background gray, but all of my OpenGL screenshots seem to accept magenta as their favorite color, maybe because I use SFML for the window ?).

However, I get the following:

I'm at a loss. Here is the corresponding code that I use, first for setting up buffer objects (I allocate a lot of memory according to the recommendation of this guy for allocating 4-8 MB)
GLuint WorldBuffer;
GLuint IndexBuffer;
...
glGenBuffers(1, &WorldBuffer);
glBindBuffer(GL_ARRAY_BUFFER, WorldBuffer);
int SizeInBytes = 1024 * 2048;
glBufferData(GL_ARRAY_BUFFER, SizeInBytes, NULL, GL_STATIC_DRAW);
glGenBuffers(1, &IndexBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBuffer);
SizeInBytes = 1024 * 2048;
glBufferData(GL_ELEMENT_ARRAY_BUFFER, SizeInBytes, NULL, GL_STATIC_DRAW);
. , CreateVertexArray() , 3 3 ( - , ):
std::vector<float>* VertArray = new std::vector<float>;
pWorld->CreateVertexArray(VertArray);
unsigned short Indice = 0;
for (int i = 0; i < VertArray->size(); ++i)
{
std::cout << (*VertArray)[i] << std::endl;
glBufferSubData(GL_ARRAY_BUFFER, i * sizeof(float), sizeof(float), &((*VertArray)[i]));
glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, i * sizeof(unsigned short), sizeof(unsigned short), &(Indice));
++Indice;
}
delete VertArray;
Indice -= 1;
:
glBindBuffer(GL_ARRAY_BUFFER, WorldBuffer);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, IndexBuffer);
glEnableClientState(GL_VERTEX_ARRAY);
glVertexPointer(3, GL_FLOAT, 0, 0);
glNormalPointer(GL_FLOAT, 0, 0);
glDrawElements(GL_TRIANGLES, Indice, GL_UNSIGNED_SHORT, 0);
glDisableClientState(GL_VERTEX_ARRAY);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
- , , glVertexPointer() glNormalPointer() ( - , Songho 0 - ?) . 0; . / . BUFFER_OFFSET(0) BUFFER_OFFSET(12), , , BUFFER_OFFSET() undefined.
, glDrawElements() , , Songho 0. &IndexBuffer 0, - , .
- , , -, ? !