why is opengl not using the correct data for positions when using more than 1 attribute the vertex data looks like this:
float vertices[] = {
0.5f, 0.5f, 0.0f, 1.0f, 0.0f, 0.0f, // top right
0.5f, -0.5f, 0.0f, 0.0f, 1.0f, 0.0f, // bottom right
-0.5f, -0.5f, 0.0f, 0.0f, 0.0f, 1.0f, // bottom left
-0.5f, 0.5f, 0.0f, 0.0f, 0.5f, 0.0f // top left
};
the first three values of each vertex are position values and the last three are colour values making the vbo vao and indexbuffer looks like this:
int EBO;
EBO = glGenBuffers();
int VAO;
VAO = glGenVertexArrays();
glBindVertexArray(VAO);
int VBO = glGenBuffers();
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, vertices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices, GL_STATIC_DRAW);
glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0);
glEnableVertexAttribArray(0);
glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0);
glEnableVertexAttribArray(1);
and the indices are this:
int indices[] = {
0, 1, 3, //first triangle
1, 2, 3 //second triangle
};
drawing looks like this:
shader.use();
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
glBindVertexArray(0);
the vertex and fragment shader:
//vertex
#version 400 core
layout (location = 0) in vec3 aPos;
layout (location = 1) in vec3 aColor;
out vec3 ourColor;
void main()
{
gl_Position = vec4(aPos.x, aPos.y, aPos.z, 1.0);
ourColor = aColor;
}
//fragment
#version 400 core
out vec4 FragColor;
in vec3 ourColor;
void main()
{
FragColor = vec4(ourColor, 1.0f);
}
The result should be 2 triangles forming a quad which is coloured with the colour values given in attribute 1
but currentely it looks like this:
https://drive.google.com/file/d/1ajSlSiSjpl-Ku6C53aQXFwKtzhSdIIWi/view?usp=sharingi also dont know where the second triangle went
when i try it without the colour values it does what its supposed to do except without color as no colour given
How do i get opengl to use the correct values