I'm relearning OpenGL in its modern form using https://learnopengl.com
Inspired by the coordinate systems lesson https://learnopengl.com/Getting-started/Coordinate-Systems I started modifying their sample code to try and create a glorified cuboctahedron. Here's my attempt. Everything not shown here is, to the best of my knowledge, the way they provided it. My code is intended to describe six faces of a cube, either connected or exploded depending on the relative values of a and b. However, it draws nonsense, connecting things in a way that makes no sense. Here is what I see using only four sets of indices:
Seems to me, the second pair of triplets should refer to the second face of the cube, and should produce two triangles that are at the very least coplanar! How did they come to be folded in the middle?? The first pair of triangles produce a distorted trapezoid instead of outlining the corners of a square, which equally surprises me.
Someone please enlighten me, why I got this instead!
In my main program:
// these govern the shape of the expanded cube solid
// if equal, it becomes a cube
float a = 0.4;
float b = 0.4;
float cuboctavertices[] = {
a, a, b, //0
a, -a, b,
-a, -a, b,
-a, a, b,
b, a, a, //4
b, a, -a,
b, -a, -a,
b, -a, a,
a, a, -b, //8
a, -a, -b,
-a, -a, -b,
-a, a, -b,
-b, a, a, //12
-b, a, -a,
-b, -a, -a,
-b, -a, a,
a, b, a, //16
a, b, -a,
-a, b, -a,
-a, b, a,
a, -b, a,
a, -b, -a,
-a, -b, -a,
-a, b, a
};
unsigned int cuboctaindices[] = {
0, 1, 2, // first triangle
1, 2, 3, // second triangle
4, 5, 6,
5, 6, 7,
};
unsigned int VBO, VAO, EBO;
glGenVertexArrays(1, &VAO);
glGenBuffers(1, &VBO);
glGenBuffers(1, &EBO);
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glBufferData(GL_ARRAY_BUFFER, sizeof(cuboctavertices), cuboctavertices, GL_STATIC_DRAW);
//glBufferData(GL_ARRAY_BUFFER, sizeof(cubices), cubices, GL_STATIC_DRAW);
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO);
glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(cuboctaindices), cuboctaindices, GL_STATIC_DRAW);
In my render loop:
// render container
glBindVertexArray(VAO);
glDrawElements(GL_TRIANGLES, 12, GL_UNSIGNED_INT, 0);