1.首先构建窗口(直接按模板来)
2.用定义的shader类来创建shader:
shader shader1("vertex.vs", "fragment.fs");
vertexshader代码如下,将坐标设为颜色:
#version 330 core
layout (location = 0) in vec3 apos;
out vec4 ourcolor;
uniform mat4 transform;
void main()
{
gl_Position = transform * vec4(apos,1.0);
ourcolor = gl_Position;
}
fragmentshader代码如下:
#version 330 core
in vec4 ourcolor;
out vec4 Fragcolor;
void main()
{
Fragcolor =vec4(1-ourcolor.x, 1-ourcolor.y, 1-ourcolor.z,1.0f);
}
3.之后建立两个三角形的坐标,分别用两个VAO、VBO管理
float firstvertices[] = {
0.0f,0.5f,0.0f,
0.5f,-0.5f,0.0f,
-0.5f,-0.5f,0.0f
};
float secondvertices[] = {
0.5f,0.5f,0.0f,
-0.5f,0.5f,0.0f,
0.0f,-0.5f,0.0f
};
unsigned int VAO[2], VBO[2];