title: Only the last object of a vector is drawn when they should all be drawn
body: <p>I have an Application object that has a vector of GameChar objects as one of its member variables. This GameChar objects contain a GLbatch that is initialized in the constructor and drawn when you call the draw method of the GameChar object. When the program starts I create an application object and three GameChar objects, and I push the GameChar's into the Application object's vector with the push_back() method. Then, inside a game loop, I iterate through the vector and call the draw method of all I'ts objects. The problem is that only the object that was last put in the vector gets drawn. I have assured that the vector is iterated correctly, and that the draw method is called on all the objects, but no matter in what order I call this draw methods (I have tried to iterate the vector from end to start to assure this), only the object that was last inserted to the vector gets drawn.</p>
  
  <p>Here is the code that creates the application and GameChar objects (the constructor gets the arguments in this order: width,height,x,y):</p>
  
  <pre><code>Application app;
  GameChar character(0.5f,0.5f,0.0f,0.0f);
  GameChar character2(0.5f,0.5f,0.5f,0.5f);
  GameChar character3(0.5f,0.5f,-1.0f,-1.0f);
  app.characters.push_back(character);
  app.characters.push_back(character2);
  app.characters.push_back(character3);
  </code></pre>
  
  <p>And this is the loop:</p>
  
  <pre><code>while (1)
  {
      vector&lt;GameChar&gt;::size_type sz=characters.size();
      unsigned int i;
      for (i=0;i&lt;sz;i++)
      {
          characters[i].update();
      }
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
  
      for (i=0;i&lt;sz;i++)
      {
  
          characters[i].draw();
      }
  
      glfwSwapBuffers();
  }
  </code></pre>
  
  <p>UPDATE:
  Here is the constructor of GameChar:</p>
  
  <pre><code>GameChar::GameChar(GLfloat lWidth,GLfloat lHeight,GLfloat lX,GLfloat lY)
  {
      xPos=lX;
      yPos=lY;
      height=lHeight;
      width=lWidth;
      if (xPos&lt;-1)
      {
          xPos=-1;
      }
      if (xPos+width&gt;1)
          xPos=1-width;
      if (yPos&lt;-1)
          yPos=-1;
      if (yPos+height&gt;1)
          yPos=1-height;
      verts[0]=xPos;
      verts[1]=yPos;
      verts[2]=0.0f;
      verts[3]=xPos+width;
      verts[4]=yPos;
      verts[5]=0.0f;
      verts[6]=xPos;
      verts[7]=yPos+height;
      verts[8]=0.0f;
      verts[9]=xPos+width;
      verts[10]=yPos+height;
      verts[11]=0.0f;
  
      batch.Begin(GL_TRIANGLE_STRIP, 4);
      batch.CopyVertexData3f(verts);
      batch.End();
  }
  </code></pre>
  
  <p>The draw method:</p>
  
  <pre><code>void GameChar::draw()
  {
      batch.Draw();
  }
  </code></pre>
  
  <p>And I've updated the game loop with the complete code.</p>
  
  <p>Also, If i try to change the code:</p>
  
  <pre><code>for (i=0;i&lt;sz;i++)
  {
      characters[i].draw();
  }
  </code></pre>
  
  <p>with this code:</p>
  
  <pre><code>for (i=0;i&lt;sz;i++)
  {
      GLBatch batch;
      batch=characters[i].batch;
      batch.Draw();
  }
  </code></pre>
  
  <p>No square gets drawn. I really find all this a nonsense</p>
  
  <p>ANOTHER UPDATE:</p>
  
  <p>If I pop_back the third object after pushing it in, like this:</p>
  
  <pre><code>Application app;
  GameChar character(0.5f,0.5f,0.0f,0.0f);
  GameChar character2(0.5f,0.5f,0.5f,0.5f);
  GameChar character3(0.5f,0.5f,-1.0f,-1.0f);
  app.characters.push_back(character);
  app.characters.push_back(character2);
  app.characters.push_back(character3);
  app.characters.pop_back();
  </code></pre>
  
  <p>nothing is drawn, but if don't push it in, like this:</p>
  
  <pre><code>Application app;
  GameChar character(0.5f,0.5f,0.0f,0.0f);
  GameChar character2(0.5f,0.5f,0.5f,0.5f);
  GameChar character3(0.5f,0.5f,-1.0f,-1.0f);
  app.characters.push_back(character);
  app.characters.push_back(character2);
  </code></pre>
  
  <p>The second character is drawn. So I think the problem is that the characters that are already in the vector are invalidated when a new one is pushed, but I don't know why this happens, or how to fix it</p>