我已经弄清楚如何添加着色器,目前正在尝试学习 GLSL。我不能给你举个例子,因为我什至不知道如何渲染一个矩形。我已经阅读了各种文章,但仍然不知道该怎么做。此外,我应该使用什么片段和顶点着色器?
我找不到从哪里获得 PNGdecoder,我在网上看到的所有内容都说要使用它。
这是我渲染矩形的尝试:
int VBO;
VAO=glGenVertexArrays();
VBO=glGenBuffers();
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
glEnableVertexAttribArray(0);
glBindVertexArray(0);
glClearColor(1.0f,1.0f,1.0f,1.0f);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
这里是我使用的顶点着色器:
#version 330 core
layout (location = 0) in vec3 aPos; // the position variable has attribute position 0
out vec4 vertexColor; // specify a color output to the fragment shader
void main()
{
gl_Position = vec4(aPos, 1.0); // see how we directly give a vec3 to vec4's constructor
vertexColor = vec4(0.5, 0.0, 0.0, 1.0); // set the output variable to a dark-red color
}
这是我使用的片段着色器:
#version 330 core
out vec4 FragColor;
in vec4 vertexColor; // the input variable from the vertex shader (same name and same type)
void main()
{
FragColor = vertexColor;
}