title: Can you do this with vertex arrays OpenGL 4.4?
body: <p>I'm loading a Collada (.dae file) and the model has 2 objects. The first which is a cloth with alot of vertices with a light blue material.
  And the second a box which the cloth is supposed to fold around as it falls down.</p>
  
  <p>This is supposed to be a 250 frame animation, but I'm not sure if it actually is or not. When I load it into Assimp's <code>aiScene*</code> it says <code>HasAnimation() == 0</code>... It also says that the mesh for the cloth has no color, with the <code>HasVertexColors() == 0</code> Which has me worried I have to take another look at exporting it. I don't know, maybe you can tell?
  I'll link it on an external side as it is too large for this post. (Sorry for that)</p>
  
  <p>Falling Cloth (Collada animation .dae):
  <a href="http://pastebin.com/54LkKq8k" rel="nofollow">http://pastebin.com/54LkKq8k</a></p>
  
  <p>My problem is that I don't see the light blue cloth, and the box is black, as in <code>(0, 0, 0)</code>...</p>
  
  <p>Initializing VBO:</p>
  
  <pre><code>void AssimpMesh::initMesh(aiMesh *mesh, MeshData *data) {
      //Buffer for temporary storage of new ids
      GLuint id;
  
      //Make vertex array
      glGenVertexArrays(1, &amp;id);
      data-&gt;meshArray = id;
  
      //Tell OpenGL to use this array
      glBindVertexArray(id);
  
      //Assign vertices
      if (mesh-&gt;HasPositions()) {
          //Make buffer
          glGenBuffers(1, &amp;id);
          data-&gt;buffers.push_back(id);
          data-&gt;bufferNames.push_back("Positions");
  
          //Set buffer data
          glBindBuffer(GL_ARRAY_BUFFER, id);
          glBufferData(GL_ARRAY_BUFFER, sizeof(aiVector3D) * mesh-&gt;mNumVertices, &amp;mesh-&gt;mVertices[0], GL_STATIC_DRAW);
  
          //Set shader attribute data
          glEnableVertexAttribArray(VBO_VERTEX);
          glVertexAttribPointer(VBO_VERTEX, 3, GL_FLOAT, GL_FALSE, NULL, NULL);
      }
  
      //Assign colors
      if (mesh-&gt;HasVertexColors(0)) {
          //Make buffer
          glGenBuffers(1, &amp;id);
          data-&gt;buffers.push_back(id);
          data-&gt;bufferNames.push_back("Colors");
  
          //Set buffer data
          glBindBuffer(GL_ARRAY_BUFFER, id);
          glBufferData(GL_ARRAY_BUFFER, sizeof(aiColor4D) * mesh-&gt;mNumVertices, &amp;mesh-&gt;mColors[0], GL_STATIC_DRAW);
  
          //Set shader attribute data
          glEnableVertexAttribArray(VBO_COLOR);
          glVertexAttribPointer(VBO_COLOR, 4, GL_FLOAT, GL_FALSE, NULL, NULL);
      }
  
      //Assign texture coords
      if (mesh-&gt;HasTextureCoords(0)) {
          //Make buffer
          glGenBuffers(1, &amp;id);
          data-&gt;buffers.push_back(id);
          data-&gt;bufferNames.push_back("TextureCoords");
  
          //Set buffer data
          glBindBuffer(GL_ARRAY_BUFFER, id);
          glBufferData(GL_ARRAY_BUFFER, sizeof(aiVector3D) * mesh-&gt;mNumVertices, &amp;mesh-&gt;mTextureCoords[0], GL_STATIC_DRAW);
  
          //Set shader attribute data
          glEnableVertexAttribArray(VBO_TEXCORD);
          glVertexAttribPointer(VBO_TEXCORD, 3, GL_FLOAT, GL_FALSE, NULL, NULL);
      }
  
      //Assign colors
      if (mesh-&gt;HasNormals()) {
          //Make buffer
          glGenBuffers(1, &amp;id);
          data-&gt;buffers.push_back(id);
          data-&gt;bufferNames.push_back("Normals");
  
          //Set buffer data
          glBindBuffer(GL_ARRAY_BUFFER, id);
          glBufferData(GL_ARRAY_BUFFER, sizeof(aiVector3D) * mesh-&gt;mNumVertices, &amp;mesh-&gt;mNormals[0], GL_STATIC_DRAW);
  
          //Set shader attribute data
          glEnableVertexAttribArray(VBO_NORMAL);
          glVertexAttribPointer(VBO_NORMAL, 3, GL_FLOAT, GL_FALSE, NULL, NULL);
      }
  
      if (mesh-&gt;HasFaces()) {
          vector &lt;unsigned int&gt; indices;
          aiFace face;
          for (int i = 0; i &lt; mesh-&gt;mNumFaces; i++) {
              face = mesh-&gt;mFaces[i];
              for (int j = 0; j &lt; face.mNumIndices; j++) {
                  indices.push_back(face.mIndices[j]);
              }
          }
  
          //Make buffer
          glGenBuffers(1, &amp;id);
          data-&gt;buffers.push_back(id);
          data-&gt;bufferNames.push_back("Faces");
  
          //Set buffer data
          glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, id);
          glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(unsigned int) * indices.size(), &amp;indices.front(), GL_STATIC_DRAW);
      }
  
      //Unbind vertex array
      glBindVertexArray(NULL);
  }
  </code></pre>
  
  <p>Draw model:</p>
  
  <pre><code>void AssimpMesh::draw() {
      //Draw all vertex arrays
      aiMesh *mesh;
      aiFace face;
      MeshData *data;
      for (int i = 0; i &lt; meshes.size(); i++) {
          mesh = scene-&gt;mMeshes[i];
          face = mesh-&gt;mFaces[0];
          data = meshes[i];
  
          //Tell OpenGL to use this array
          glBindVertexArray(data-&gt;meshArray);
  
          //Tell OpenGL which shader to use
          glUseProgram(data-&gt;program);
  
          //Draw the elements of the array
          glDrawElements(GL_TRIANGLES, face.mNumIndices * mesh-&gt;mNumFaces, GL_UNSIGNED_INT, 0);
      }
  
      //Unbind vertex array
      glBindVertexArray(NULL);
  
      //Unbind shader
      glUseProgram(NULL);
  }
  </code></pre>
  
  <p>Vertex shader:</p>
  
  <pre><code>#version 120
  
  attribute vec3 vertex;
  attribute vec4 color;
  attribute vec3 texCoord;
  attribute vec3 normal;
  
  uniform mat4 transform;
  
  varying vec3 shared_color;
  varying vec2 shared_texCoord;
  varying vec3 shared_normal;
  
  void main() {
      gl_Position = transform * vec4(vertex, 1.0);
  
      //Send data to fragment shader
      shared_color = color.xyz;
      shared_texCoord = texCoord.xy;
      shared_normal = (transform * vec4(normal, 0.0)).xyz;
  }
  </code></pre>
  
  <p>Fragment shader:</p>
  
  <pre><code>#version 120
  
  uniform sampler2D diffuse;
  uniform int flagTexture;
  
  varying vec3 shared_color;
  varying vec2 shared_texCoord;
  varying vec3 shared_normal;
  
  void main() {
      vec4 color = vec4(shared_color, 1);
      vec4 texture = texture2D(diffuse, shared_texCoord);
      vec4 finalColor = color;
  
      if (flagTexture &gt;= 1) {
          finalColor = vec4(mix(color.rgb, texture.bgr, texture.a), 1);
          //finalColor = color * texture;
      }
  
      float shade = 0;
      if (shade &gt;= 1) {
          vec3 lightPosition = vec3(0, 0, -1);
          float shadowDarkness = 0.8;
          vec3 actualLightPos = vec3(-lightPosition.x, lightPosition.y, lightPosition.z);
          float lightStrength = clamp(dot(actualLightPos, shared_normal), 1 - shadowDarkness, 1.0);
          vec4 litColor = finalColor * lightStrength;
          finalColor = litColor;
      }
  
      gl_FragColor = finalColor;
  }
  </code></pre>