title: Issue in drawing ellipsoid with OpenGL
body: <p>this is the code I use to create and draw an ellipsoid with OpenGL with shader</p>
  
  <pre><code>  const float _2pi = 2.0f * M_PI;
  
    std::vector&lt;glm::vec3&gt; positions;
    std::vector&lt;glm::vec3&gt; normals;
    std::vector&lt;glm::vec2&gt; textureCoords;
  
    for(int i = 0; i &lt;= stacks; ++i) {
  
      // V texture coordinate
      float V = i / (float)stacks;
      float phi = V * M_PI;
  
      for( int j = 0; j &lt;= slices; ++j) {
  
        // U texture coordinate
        float U = j / (float)slices;
        float theta = U * _2pi;
  
        float X = a * cos(theta) * cos(phi);
        float Y = b * cos(theta) * sin(phi);
        float Z = c * sin(theta);
  
        positions.push_back( glm::vec3( X, Y, Z) );
        normals.push_back( glm::vec3(X, Y, Z) );
        textureCoords.push_back( glm::vec2(U, V) );
  
      }
  
    }
  
    // Now generate the index buffer
    std::vector&lt;GLuint&gt; indicies;
  
    for(int i=0; i &lt;slices*stacks+slices; ++i) {
  
      indicies.push_back(i);
      indicies.push_back(i + slices + 1);
      indicies.push_back(i + slices);
  
      indicies.push_back(i + slices + 1);
      indicies.push_back(i);
      indicies.push_back(i + 1);
  
    }
  
    glGenVertexArrays(1, &amp;vao);
    glBindVertexArray(vao);
  
    glGenBuffers(4, vbo);
  
    glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
    glBufferData(GL_ARRAY_BUFFER, positions.size() * sizeof(glm::vec3), positions.data(), GL_STATIC_DRAW);
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
    glEnableVertexAttribArray(0);
  
    glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
    glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), normals.data(), GL_STATIC_DRAW);
    glVertexAttribPointer(2, 3, GL_FLOAT, GL_TRUE, 0, nullptr);
    glEnableVertexAttribArray(2);
  
    glBindBuffer(GL_ARRAY_BUFFER, vbo[2]);
    glBufferData(GL_ARRAY_BUFFER, textureCoords.size() * sizeof(glm::vec2), textureCoords.data(), GL_STATIC_DRAW);
    glVertexAttribPointer(8, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
    glEnableVertexAttribArray(8);
  
    glBindBuffer( GL_ELEMENT_ARRAY_BUFFER, vbo[3]);
    glBufferData( GL_ELEMENT_ARRAY_BUFFER, indicies.size() * sizeof(GLuint), indicies.data(), GL_STATIC_DRAW);
  
    glBindVertexArray(0);
    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  </code></pre>
  
  <p>while this is the code that I use to render it:</p>
  
  <pre><code>  glBindVertexArray(vao);
  
    glEnableVertexAttribArray(0);
  
    if(style == glObject::STYLE::WIREFRAME) glDrawElements(GL_LINES,     (slices * stacks + slices) * 6, GL_UNSIGNED_INT, nullptr);
    if(style == glObject::STYLE::SOLID)     glDrawElements(GL_TRIANGLES, (slices * stacks + slices) * 6, GL_UNSIGNED_INT, nullptr);
  
    glBindVertexArray(0);
  </code></pre>
  
  <p>It seems to work but I have some issue. 
  Looking the image it is possible to see some vertex in the wrong position.
  I think that is something related to the indicies but I'm not sure.
  I have notice that depends by the number of stacks or slices that I use</p>
  
  <p><a href="https://i.stack.imgur.com/HJ6AD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HJ6AD.png" alt="enter image description here"></a></p>
  
  <p><strong><em>UPDATE:</em></strong></p>
  
  <p>I take into account the suggestion of @Rabbid76 and this is the result.
  No more degenerated vertex and triangles in the rendering.
  However the rendering is not equal to the one of @Rabbid76 there is like a rotation of the vertex.</p>
  
  <p><a href="https://i.stack.imgur.com/d7cN0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d7cN0.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/dAdvE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dAdvE.png" alt="enter image description here"></a></p>
  
  <p><strong><em>FINAL:</em></strong></p>
  
  <p>This is the creation vertex and indices code:</p>
  
  <pre><code>      std::vector&lt;glm::vec3&gt; positions;
        std::vector&lt;glm::vec3&gt; normals;
        std::vector&lt;glm::vec2&gt; textureCoords;
  
        for(int i = 0; i &lt;= stacks; ++i) {
  
          // V texture coordinate.
          float V = i / (float)stacks;
          float phi = V * M_PI;
  
          for( int j = 0; j &lt;= slices; ++j) {
  
            // U texture coordinate.
            float U = j / (float)slices;
            float theta = U * 2.0f * M_PI;
  
            float X = cos(theta) * sin(phi);
            float Y = cos(phi);
            float Z = sin(theta) * sin(phi);
  
            positions.push_back( glm::vec3( X, Y, Z) * radius );
            normals.push_back( glm::vec3(X, Y, Z) );
            textureCoords.push_back( glm::vec2(U, V) );
  
          }
  
        }
  
        // Now generate the index buffer
        std::vector&lt;GLuint&gt; indicies;
  
        int noPerSlice = slices + 1;
  
        for(int i=0; i &lt; stacks; ++i) {
  
          for (int j=0; j &lt; slices; ++j) {
  
            int start_i = (i * noPerSlice) + j;
  
            indicies.push_back( start_i );
            indicies.push_back( start_i + noPerSlice + 1 );
            indicies.push_back( start_i + noPerSlice );
  
            indicies.push_back( start_i + noPerSlice + 1 );
            indicies.push_back( start_i );
            indicies.push_back( start_i + 1 );
  
          }
  
        }
  
        glGenVertexArrays(1, &amp;vao);
        glBindVertexArray(vao);
  
        glGenBuffers(4, vbo);
  
        glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
        glBufferData(GL_ARRAY_BUFFER, positions.size() * sizeof(glm::vec3), positions.data(), GL_STATIC_DRAW);
        glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
        glEnableVertexAttribArray(0);
  
        glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
        glBufferData(GL_ARRAY_BUFFER, normals.size() * sizeof(glm::vec3), normals.data(), GL_STATIC_DRAW);
        glVertexAttribPointer(2, 3, GL_FLOAT, GL_TRUE, 0, nullptr);
        glEnableVertexAttribArray(2);
  
        glBindBuffer(GL_ARRAY_BUFFER, vbo[2]);
        glBufferData(GL_ARRAY_BUFFER, textureCoords.size() * sizeof(glm::vec2), textureCoords.data(), GL_STATIC_DRAW);
        glVertexAttribPointer(8, 2, GL_FLOAT, GL_FALSE, 0, nullptr);
        glEnableVertexAttribArray(8);
  
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, vbo[3]);
        glBufferData(GL_ELEMENT_ARRAY_BUFFER, indicies.size() * sizeof(GLuint), indicies.data(), GL_STATIC_DRAW);
  
        glBindVertexArray(0);
        glBindBuffer(GL_ARRAY_BUFFER, 0);
        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
  </code></pre>
  
  <p>This is the rendering one:</p>
  
  <pre><code>    glBindVertexArray(vao);
  
      glEnableVertexAttribArray(0);
  
      if(style == glObject::STYLE::WIREFRAME) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      if(style == glObject::STYLE::SOLID)     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  
      glDrawElements(GL_TRIANGLES, (slices * stacks + slices) * 6, GL_UNSIGNED_INT, nullptr);
  
      glBindVertexArray(0);
  </code></pre>