4. Vertex Buffers and Draw a Triangle in OpenGL

1. What is vertex buffer

![[Vertex Buffers]]

2. Draw a triangle

  1. The easiest way
    1
    2
    3
    4
    5
    glBegin(GL_TRIANGLES);
    glVertex2f(-0.5f, -0.5f);
    glVertex2f(0.0f, 0.0f);
    glVertex2f(0.5f, -0.5f);
    glEnd();
    In this script,we tell the shader that we want to draw a traingle and give it three points,then it draw the traingle for us.

Bind-glBindBuffer

1
2
glBindBuffer(GL_ARRAY_BUFFER, buffer);
//This code means that the current time you bind with sth,so you don't need to cite which buffer you will draw.Just bind it.

It is like PS,before you draw sth.You need to specifit which layer you will work on, then you work.
This is contextual, and this is ==state machine==.