Draw Sphere - Reihenfolge der Eckpunkte

Ich möchte in reiner OpenGL ES 2.0 Kugel ohne Motoren zeichnen. Ich schreibe den nächsten Code:

 int GenerateSphere (int Slices, float radius, GLfloat **vertices, GLfloat **colors) {
 srand(time(NULL));
 int i=0, j = 0;
 int Parallels = Slices ;
 float tempColor = 0.0f;    
 int VerticesCount = ( Parallels + 1 ) * ( Slices + 1 );
 float angleStep = (2.0f * M_PI) / ((float) Slices);

 // Allocate memory for buffers
 if ( vertices != NULL ) {
    *vertices = malloc ( sizeof(GLfloat) * 3 * VerticesCount );
 }
 if ( colors != NULL) {
    *colors = malloc( sizeof(GLfloat) * 4 * VerticesCount);
 }

 for ( i = 0; i < Parallels+1; i++ ) {
     for ( j = 0; j < Slices+1 ; j++ ) {

         int vertex = ( i * (Slices + 1) + j ) * 3;

         (*vertices)[vertex + 0] = radius * sinf ( angleStep * (float)i ) *
                    sinf ( angleStep * (float)j );
         (*vertices)[vertex + 1] = radius * cosf ( angleStep * (float)i );
         (*vertices)[vertex + 2] = radius * sinf ( angleStep * (float)i ) *
                        cosf ( angleStep * (float)j );
         if ( colors ) {
                int colorIndex = ( i * (Slices + 1) + j ) * 4;
                tempColor = (float)(rand()%100)/100.0f;

                (*colors)[colorIndex + 0] =  0.0f;
                (*colors)[colorIndex + 1] =  0.0f;
                (*colors)[colorIndex + 2] =  0.0f;
                (*colors)[colorIndex + (rand()%4)] = tempColor;
                (*colors)[colorIndex + 3] =  1.0f;
            }
        }
    }
    return VerticesCount;
}

Ich zeichne es mit dem nächsten Code:

glDrawArrays(GL_TRIANGLE_STRIP, 0, userData->numVertices);

Wobei userData-> numVertices - VerticesCount von der Funktion GenerateSphere. Aber auf dem Bildschirm werden serielle Dreiecke gezeichnet, das ist keine Kugelapproximation! Ich denke, ich muss Eckpunkte nummerieren und die OpenGL ES 2.0-Funktion glDrawElements () verwenden (mit Array, enthielt Anzahl Eckpunkte). Auf dem Bildschirm gezeichnete Dreieckserien sind jedoch keine Näherungswerte für die Kugel. Wie kann ich eine Kugelapproximation zeichnen? Wie werden Ordnungsscheitelpunkte (Indizes in OpenGL ES 2.0-Begriffen) angegeben?

Antworten auf die Frage(2)

Ihre Antwort auf die Frage