4. Vertex Buffers and Draw a Triangle in OpenGL
4. Vertex Buffers and Draw a Triangle in OpenGL
Rif1. What is vertex buffer
![[Vertex Buffers]]
2. Draw a triangle
- The easiest wayIn 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.
1
2
3
4
5glBegin(GL_TRIANGLES);
glVertex2f(-0.5f, -0.5f);
glVertex2f(0.0f, 0.0f);
glVertex2f(0.5f, -0.5f);
glEnd();
Bind-glBindBuffer
1 | glBindBuffer(GL_ARRAY_BUFFER, buffer); |
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==.