I'm getting a distorted red triangle when trying to display a red triangle with 3 vertices (at (-0.5,-0.5) (0.5,-0.5) (0,0.5)) I'm passing to the shader with this code
public void LoadData<T>(BufferConfig<T> config) where T : struct, IVertex
{
Bind();
GL.BufferData(config.Target, config.VertexCount * config.Layout.SizeOfVertex, config.Vertices, config.Usage);
int offset = 0;
for (int i = 0; i < config.Layout.Attribs.Length; i++)
{
GL.EnableVertexAttribArray(i);
GL.VertexAttribPointer(
i,
config.Layout.Attribs[i].ElementCount,
config.Layout.Attribs[i].ElementType,
config.Layout.Attribs[i].IsNormalized,
config.Layout.Attribs[i].Stride,
offset
);
offset += config.Layout.Attribs[i].Stride;
}
Unbind();
}
The vertex consists of 2 Vector4's respectively representing position and colour, I have tried debugging it and the values seem fine as there are 2 attributes, position and color, the loop runs 2 times,
1st iteration: index = 0, count = 4, type = float, normalized = false, stride = 16, pointer = 0
2nd iteration: index = 1, count = 4, type = float, normalized = false, stride = 16, pointer = 16
Why exactly does this look like in the image ?
EDIT:
Vertex shader
#version 450 core
layout(location = 0) in vec4 position;
layout(location = 1) in vec4 color;
out vec4 vs_color;
void main(void)
{
gl_Position = position;
vs_color = color;
}
Fragment shader
#version 450 core
in vec4 vs_color;
out vec4 fragColor;
void main(void)
{
fragColor = vs_color;
}
Vertices
r1.AddVertices(new CVertex[] {
new CVertex(new Vector4(-0.5f,-0.5f,0f,1f), new Vector4(1f,0f,0f,1f)),
new CVertex(new Vector4(0.5f,-0.5f,0f,1f), new Vector4(0f,1f,0f,1f)),
new CVertex(new Vector4(0f,0.5f,0f,1f), new Vector4(0f,0f,1f,0f))
});