int main(){

    1. unsigned int VBO, VAO, EBO;
    2. glGenVertexArrays(1, &VAO);//一个缓冲ID生成 VAO1
    3. glGenBuffers(1, &VBO);//VBO1
    4. glGenBuffers(1, &EBO);
    5. glBindVertexArray(VAO);////绑定缓冲对象类型
    6. glBindBuffer(GL_ARRAY_BUFFER, VBO);
    7. glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);//绑定数据属性
    8. glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
    9. glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW);
    10. //VAO被关联到Data,然后设置顶点属性指针属性,然后EnableVertexAttribArray
    11. glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
    12. glEnableVertexAttribArray(0);
    13. // color attribute
    14. glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
    15. glEnableVertexAttribArray(1);
    16. // texture coord attribute
    17. glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
    18. glEnableVertexAttribArray(2);
    19. // You can unbind the VAO afterwards so other VAO calls won't accidentally modify this VAO, but this rarely happens. Modifying other
    20. // VAOs requires a call to glBindVertexArray anyways so we generally don't unbind VAOs (nor VBOs) when it's not directly necessary.
    21. // glBindVertexArray(0);
    22. // bind the VAO (it was already bound, but just to demonstrate): seeing as we only have a single VAO we can
    23. // just bind it beforehand before rendering the respective triangle; this is another approach.

    while(){

    1. glBindVertexArray(VAO);
    2. glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);