title: C++ OpenGL mesh rendering
body: <p>I know there are a lot of resources about this on the internet but they didn't quite seem to help me.</p>
  
  <p><strong>What I want to achieve:</strong><br/>
  I am baking a mesh from data which stores the vertices inside a <code>vector&lt;Vector3&gt;</code>.<br/>
  (<code>Vector3</code> is a <code>sctruct</code> containg <code>float x, y, z</code>)<br/>
  It stores triangles in a <code>map&lt;int, vector&lt;int&gt;&gt;</code><br>
  (the key of the map is the submesh and the <code>vector&lt;int&gt;</code> the triangles)<br>
  the uv inside a <code>vector&lt;Vector2&gt;</code><br>
  (<code>Vector2</code> is a <code>struct</code> containing <code>float x, y</code>)<br>
  and a color value in <code>vector&lt;Color&gt;</code><br>
  (the color value applies to vertices like the uv does)<br>
  <br>
  Now I want to write a code that can read that data and draw it to the screen with maximum performance<br>
  <br>
  <strong>What I got:</strong><br></p>
  
  <pre><code>static void renderMesh(Mesh mesh, float x, float y, float z) {
      if (mesh.triangles.empty()) return;
      if (mesh.vertices.empty()) return;
      if (mesh.uvs.empty()) return;
      glColor3f(1, 1, 1);
      typedef std::map&lt;int, std::vector&lt;int&gt;&gt;::iterator it_type;
      for (it_type iterator = mesh.triangles.begin(); iterator != mesh.triangles.end(); iterator++) {
          int submesh = iterator-&gt;first;
          if (submesh &lt; mesh.textures.size()) glBindTexture(GL_TEXTURE_2D, mesh.textures[submesh].id);
          else glBindTexture(GL_TEXTURE_2D, 0);
          glEnable(GL_BLEND);
          glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
          for (int i = 0; i &lt; iterator-&gt;second.size(); i += 3) {
              int t0 = iterator-&gt;second[i + 0];
              int t1 = iterator-&gt;second[i + 1];
              int t2 = iterator-&gt;second[i + 2];
              Vector3 v0 = mesh.vertices[t0];
              Vector3 v1 = mesh.vertices[t1];
              Vector3 v2 = mesh.vertices[t2];
              Color c0 = mesh.vertexColors[t0];
              Color c1 = mesh.vertexColors[t1];
              Color c2 = mesh.vertexColors[t2];
              Vector2 u0 = mesh.uvs[t0];
              Vector2 u1 = mesh.uvs[t1];
              Vector2 u2 = mesh.uvs[t2];
              glBegin(GL_TRIANGLES);
              glColor4f(c0.r / 255.0f, c0.g / 255.0f, c0.b / 255.0f, c0.a / 255.0f); glTexCoord2d(u0.x, u0.y); glVertex3f(v0.x + x, v0.y + y, v0.z + z);
              glColor4f(c1.r / 255.0f, c1.g / 255.0f, c1.b / 255.0f, c1.a / 255.0f); glTexCoord2d(u1.x, u1.y); glVertex3f(v1.x + x, v1.y + y, v1.z + z);
              glColor4f(c2.r / 255.0f, c2.g / 255.0f, c2.b / 255.0f, c2.a / 255.0f); glTexCoord2d(u2.x, u2.y); glVertex3f(v2.x + x, v2.y + y, v2.z + z);
              glEnd();
              glColor3f(1, 1, 1);
          }
      }
  }
  </code></pre>
  
  <p><strong>The problem:</strong><br>
  I found out that the way I render is not the best way and that you can achieve higher performance with <code>glDrawArrays</code> (I think it was called).<br>
  Could you help me rewriting my code to fit with glDrawArrays, since what I found so far on the internet did not help me too much.<br>
  <br>
  Thanks, and if there is any more information needed just ask.<br>
  <br></p>