Home > Mobile >  Turn to QT opengl 3 d graphics
Turn to QT opengl 3 d graphics

Time:09-22

I'm not very understanding of this code below, please help me to explain, thank you!

 
Unsigned int handle [3].
GlGenBuffers (3, handle);

GlBindBuffer (GL_ARRAY_BUFFER, handle [0]);
ElementCount glBufferData (GL_ARRAY_BUFFER, 9 * * sizeof (float), node, GL_STATIC_DRAW);

GlBindBuffer (GL_ARRAY_BUFFER, handle [1]);
ElementCount glBufferData (GL_ARRAY_BUFFER, 9 * * sizeof (float), normal, GL_STATIC_DRAW);

GlBindBuffer (GL_ELEMENT_ARRAY_BUFFER, handle [2]);
ElementCount glBufferData (GL_ELEMENT_ARRAY_BUFFER, 3 * * sizeof (unsigned int), el, GL_STATIC_DRAW);


Vao. The create ();
Vao. The bind ();

GlEnableVertexAttribArray (0);//Vertex position
GlBindBuffer (GL_ARRAY_BUFFER, handle [0]);
GlVertexAttribPointer ((GLuint) 0, 3, GL_FLOAT, GL_FALSE, 0, (the NULL (GLubyte *) + (0)));

GlEnableVertexAttribArray (1);//Vertex normal
GlBindBuffer (GL_ARRAY_BUFFER, handle [1]);
GlVertexAttribPointer ((GLuint) 1, 3, GL_FLOAT, GL_FALSE, 0, (the NULL (GLubyte *) + (0)));

GlBindBuffer (GL_ELEMENT_ARRAY_BUFFER, handle [2]);

Vao. Release ();


In front of the code, I have been generated node, normal, el the three arrays, the node is a node, the coordinates of xyz lined up in sequence; Normal is a node normal vector; El is unit list, these three array I have repeated the debug for many times, there should be no problem,

But after generated array, followed by the code, on general meaning is bound to the cache, and then in the render () function in the display with glDrawElements,

 
Vao. The bind ();
GlDrawElements (GL_TRIANGLES, ElementCount, GL_UNSIGNED_INT, 0);
Vao. Release ();


But I don't show the correct results modified, no error, is what is displayed a mess, not according to my list is arranged in el unit,

My el ranking rules is: 123456789; 123 to form a triangle, forming a 456, 789 a, then the node and the corresponding normal is more than 9 position of xyz lined,

Also please have ace to help me and explain posted the code at the beginning, why glBindBuffer appeared six times, it's better if can explain the sentence by sentence, please thank you!!!!!! I refer to the address of the original tutorial here:
https://blog.csdn.net/chaojiwudixiaofeixia/article/details/78043051
  •  Tags:  
  • Qt
  • Related