Vertex

Vertex Input

slide_3.jpg

3-s2.0-B9780128006450500063-f06-01-9780128006450.jpg

float vertices[] = {
    -0.5f, -0.5f, 0.0f,
     0.5f, -0.5f, 0.0f,
     0.0f,  0.5f, 0.0f
};

The triangle specified in the code clip above within NDC

The triangle specified in the code clip above within NDC

<aside> 💡 OpenGL Vertex Coordinate System: [-1, +1]

</aside>

Screen Shot 2022-01-16 at 4.18.56 PM.png

Set Up Vertex Buffer

unsigned int VBO;

// 0. Generate a buffer with a buffer ID & stores into `VBO`
glGenBuffers(1, &VBO);

// 1. Bind the newly created buffer `VBO` to the GL_ARRAY_BUFFER target
//     1. buffer type of vertex buffer object -> GL_ARRAY_BUFFER
//     2. from this point on any buffer calls we make (on GL_ARRAY_BUFFER target)
//          will be used to configure the currently bound buffer
//     3. we can bind to several buffers at once as long as they have a different buffer type
glBindBuffer(GL_ARRAY_BUFFER, VBO);

// 2. Copy the previously defined `vertices` data into currently bound buffer's memory
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

// 3. Set the vertex attributes pointers
glVertexAttribPointer(attribIdx, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(float), (void*)0);
glEnableVertexAttribArray(0);  

// 4. use our shader program when we want to render an object
glUseProgram(shaderProgram);

glBufferData function specifically targeted to copy user-defined data into the currently bound buffer