我正在尝试为 3 个圆圈着色,但只出现 3 个白色圆圈。在本例中 n 为 3。每个顶点有5个点,2个位置,3个颜色
这是我认为可能存在问题的地方:
glEnableVertexAttribArray(0);
glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
glVertexAttribPointer(
0,
2,
GL_FLOAT,
GL_FALSE,
5*sizeof(float),
(void*)0
);
glEnableVertexAttribArray(1);
glVertexAttribPointer(
1,
3,
GL_FLOAT,
GL_FALSE,
5*sizeof(float),
(void*)(2*sizeof(float))
);
glDrawElements(GL_TRIANGLES, 20 * 3 * n, GL_UNSIGNED_INT, 0);
glDisableVertexAttribArray(0);
glDisableVertexAttribArray(1);
我的着色器:
#version 330 core
in vec3 Color;
out vec4 outColor;
void main()
{
outColor = vec4(Color, 1.0);
}
#version 330 core
layout(location = 0) in vec2 position;
layout(location = 1) in vec3 color
out vec3 Color
void main(){
gl_Position = vec4(position, 0.0, 1.0);
Color = color;
}
谢谢你看安迪
编辑:
layout(location = 1) in vec3 color
out vec3 Color
layout(location = 1) in vec3 color;
out vec3 Color;