So say I want a Square made of two triangles each triangle diffrent color, but I want it optimised so I use vertex indexing like so:
Summary
This text will be hidden
Summary
This text will be hidden
Summary
This text will be hidden
float testPositions[] = {
0.0f, 1.0f, 0.0f,
1.0f, 1.0f, 0.0f,
1.0f, 1.0f, 1.0f,
0.0f, 1.0f, 1.0f
};
unsigned int indices[] = {
0, 2, 3, 0, 1, 2
};
And heres my color Buffer:
float colorData[] = {
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 0.0f, 0.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f
};
(I create every buffer like this:
unsigned int bufferID;
glGenBuffers(1, &bufferID);
glBindBuffer(GL_ARRAY_BUFFER, bufferID);
glBufferData(GL_ARRAY_BUFFER, bufferData.size() * sizeof(float), bufferData,
GL_STATIC_DRAW);
glEnableVertexAttribArray(1);
glBindBuffer(GL_ARRAY_BUFFER, bufferData);
glVertexAttribPointer(
pointerAttrib,
3,
GL_FLOAT,
GL_FALSE,
0,
(void*)0
);
So I wish that my first triangle would be red and second white but the colors get set for indivial vertecies and indexes. Is there any solution to that or I just have to make some vertecies doubled?