This is the code I am using:
//
// Generate unit quad-sphere vertices and indices.
//
// res is vertex resolution.
// face_n, face_t, and face_b are basis vectors of cube faces.
//
for (s32 face_index = 0; face_index < 6; face_index++) {
s32 face_offset = face_index * SQUARE(res);
for (s32 row = 0; row < res; row++) {
for (s32 column = 0; column < res; column++) {
// Convert from range 0..1 to -1..1
f32 x = (((f32)column / (f32)(res - 1)) - 0.5f) * 2.0f;
f32 y = (((f32)row / (f32)(res - 1)) - 0.5f) * 2.0f;
V3 p = face_n[face_index] + face_t[face_index]*x + face_b[face_index]*y;
p = normalize(p);
array_add(&sphere_mesh_vertices, Vertex_XN{p, p});
// Indices.
if (row != res-1 && column!=res-1) {
u32 bottom_left = face_offset + (row * res + column);
u32 bottom_right = face_offset + (row * res + (column + 1));
u32 top_right = face_offset + ((row + 1) * res + (column + 1));
u32 top_left = face_offset + ((row + 1) * res + column);
// Triangle 1 (CCW).
array_add(&sphere_mesh_indices, bottom_left);
array_add(&sphere_mesh_indices, bottom_right);
array_add(&sphere_mesh_indices, top_right);
// Triangle 2 (CCW).
array_add(&sphere_mesh_indices, bottom_left);
array_add(&sphere_mesh_indices, top_right);
array_add(&sphere_mesh_indices, top_left);
}
}
}
}