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);

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

In Computer Graphics, using OpenGL.

 

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.

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);
Transcribed Image Text: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);
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education