glfwMakeContextCurrent(window); //! @note Set the vsync to be enabled by default glfwSwapInterval(interval: 1); float vertices[] = { }; [0]=0.5f, [1]=0.5f, [2]=0.0f, // top right [3]=0.5f, [4]=-0.5f, [5]=0.0f, [6]=-0.5f, [7]=0.5f, [8]=0.0f, // second triangle // bottom right // top left [9]=0.5f, [10]=-0.5f, [11]=0.0f, // bottom right [12]=-0.5f, [13]=-0.5f, [14]=0.0f, // bottom left [15]=-0.5f, [16]=0.5f, [17]=0.0f // top left uint32_t verticesBufferRendererID; glGenBuffers(GL_ARRAY_BUFFER, &verticesBufferRendererID); glBindBuffer(GL_ARRAY_BUFFER, verticesBuffer RendererID); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); float indices[] = { }; [0]=0, [1]=1, [2]=3, //! @note First Triangle [3]=1, [4]=2, [5]=3 //! @note Second Triangle uint32_t indicesBufferRendererID; glGenBuffers(GL_ELEMENT_ARRAY_BUFFER, &indicesBufferRendererID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesBufferRendererID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); glDrawElements (GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), GL_UNSIGNED_INT, 0);
glfwMakeContextCurrent(window); //! @note Set the vsync to be enabled by default glfwSwapInterval(interval: 1); float vertices[] = { }; [0]=0.5f, [1]=0.5f, [2]=0.0f, // top right [3]=0.5f, [4]=-0.5f, [5]=0.0f, [6]=-0.5f, [7]=0.5f, [8]=0.0f, // second triangle // bottom right // top left [9]=0.5f, [10]=-0.5f, [11]=0.0f, // bottom right [12]=-0.5f, [13]=-0.5f, [14]=0.0f, // bottom left [15]=-0.5f, [16]=0.5f, [17]=0.0f // top left uint32_t verticesBufferRendererID; glGenBuffers(GL_ARRAY_BUFFER, &verticesBufferRendererID); glBindBuffer(GL_ARRAY_BUFFER, verticesBuffer RendererID); glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); float indices[] = { }; [0]=0, [1]=1, [2]=3, //! @note First Triangle [3]=1, [4]=2, [5]=3 //! @note Second Triangle uint32_t indicesBufferRendererID; glGenBuffers(GL_ELEMENT_ARRAY_BUFFER, &indicesBufferRendererID); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indicesBufferRendererID); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); glDrawElements (GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), GL_UNSIGNED_INT, 0);
Chapter16: Graphics
Section: Chapter Questions
Problem 17RQ
Related questions
Question
In
How does having index buffers work? How do we know what indices we want to reuse, in terms of telling how that works, especially with OpenGL are going to be using those indices?
Can you emphasize both visually and emphasis on how the index buffers refer to our vertices. Like in the image, I attached for more context on what I mean.
What I cant see visually is how do you know what values should be put in the index buffer to render.
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Recommended textbooks for you
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781305480537
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT