So I have created all of the correct sphere vertices using this algorithm:
GLint total = 100;
GLfloat radius = 200;
GLfloat sphereVertices[30000];
for (int i = 0; i < total; i++)
{
float lon = map(i, 0, total, -M_PI, M_PI);
for (int j = 0; j < total; j++)
{
float lat = map(j, 0, total, -M_PI/2, M_PI/2);
sphereVertices[(i * 300) + (j * 3)] = radius * sin(lon) * cos(lat);
sphereVertices[(i * 300) + (j * 3) + 1] = radius * sin(lon) * sin(lat);
sphereVertices[(i * 300) + (j * 3) + 2] = radius * cos(lon);
}
}
But when I draw it using either GL_TRIANGLES and GL_TRIANGLE_STRIP, I'm produced with this result:
As you can see the only triangles which are being rendered are slicing through the center of the sphere. Is my math wrong? Or am I not plotting my data into my array the correct way for my glVertexAttribPointer function to read the data correctly?
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 * sizeof(GLfloat), 0);
EDIT 1:
glBindVertexArray(VAO);
glBindBuffer(GL_ARRAY_BUFFER, VBO);
glDrawArrays(GL_TRIANGLES, 0, 10000);
See Question&Answers more detail:os