title: Creating manual mesh in Ogre3d?
body: <p>I am getting a bit confused as to why my manually created mesh is not appearing correctly.  I have created the vertex and index buffers and they seem (although I am not 100% sure) to contain the correct values.</p>
  
  <p>Essentially I am creating a grid of mapSize * mapSize vetrices, at a height of 0, then creating the triangles out of them.</p>
  
  <pre><code>void TerrainGeneration::createTerrainMesh() {
    /// Create the mesh via the MeshManager
        Ogre::MeshPtr msh = Ogre::MeshManager::getSingleton().createManual("TerrainTest", "General");
    Ogre::SubMesh* sub = msh-&gt;createSubMesh();
  
    const size_t nVertices = mapSize*mapSize;
    const size_t vbufCount = 3*2*nVertices;
  
    float vertices[vbufCount];
  
    size_t vBufCounter = 0;
    for(int z = 0; z &lt; mapSize; z++) {
            for(int x = 0; x &lt; mapSize; x++) {
            //Position
        vertices[vBufCounter] = x;
        vertices[vBufCounter+1] = 0;
        vertices[vBufCounter+2] = z;
        //Normal
        vertices[vBufCounter+3] = 0;
        vertices[vBufCounter+4] = 1;
        vertices[vBufCounter+5] = 0;
  
        vBufCounter += 6;
        }
    }
  
    Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem();
        Ogre::RGBA colours[nVertices];
        Ogre::RGBA *pColour = colours;
  
    //Create triangles
    const size_t ibufCount = 6*(mapSize - 1)*(mapSize - 1);
    unsigned int faces[ibufCount];
  
    size_t iBufCounter = 0;
    for(int x=0; x &lt;= mapSize -2; x++) {
      for(int y=0; y &lt;= mapSize -2; y++) {
          faces[iBufCounter] = vertices[(y*mapSize) + x];
          faces[iBufCounter+1] = vertices[((y+1)*mapSize) + x];
          faces[iBufCounter+2] = vertices[((y+1)*mapSize) + (x+1)];
  
          faces[iBufCounter+3] = vertices[(y*mapSize) + x];
          faces[iBufCounter+4] = vertices[((y+1)*mapSize) + (x+1)];
          faces[iBufCounter+5] = vertices[(y*mapSize) + (x+1)];
  
          iBufCounter += 6;
      }
  }
  
  
  
  
  
  
  
  
  
  /// Create vertex data structure for n*n vertices shared between submeshes
      msh-&gt;sharedVertexData = new Ogre::VertexData();
      msh-&gt;sharedVertexData-&gt;vertexCount = nVertices;
  
  /// Create declaration (memory format) of vertex data
      Ogre::VertexDeclaration* decl = msh-&gt;sharedVertexData-&gt;vertexDeclaration;
      size_t offset = 0;
      // 1st buffer
      decl-&gt;addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
      offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
      decl-&gt;addElement(0, offset, Ogre::VET_FLOAT3, Ogre::VES_NORMAL);
      offset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
      /// Allocate vertex buffer of the requested number of vertices (vertexCount) 
      /// and bytes per vertex (offset)
      Ogre::HardwareVertexBufferSharedPtr vbuf = 
      Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(
      offset, msh-&gt;sharedVertexData-&gt;vertexCount, Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
      /// Upload the vertex data to the card
      vbuf-&gt;writeData(0, vbuf-&gt;getSizeInBytes(), vertices, true);
  
      /// Set vertex buffer binding so buffer 0 is bound to our vertex buffer
      Ogre::VertexBufferBinding* bind = msh-&gt;sharedVertexData-&gt;vertexBufferBinding; 
      bind-&gt;setBinding(0, vbuf);
  
      /// Allocate index buffer of the requested number of vertices (ibufCount) 
      Ogre::HardwareIndexBufferSharedPtr ibuf = Ogre::HardwareBufferManager::getSingleton().
      createIndexBuffer(
      Ogre::HardwareIndexBuffer::IT_16BIT, 
      ibufCount, 
      Ogre::HardwareBuffer::HBU_STATIC_WRITE_ONLY);
  
      /// Upload the index data to the card
      ibuf-&gt;writeData(0, ibuf-&gt;getSizeInBytes(), faces, true);
  
      /// Set parameters of the submesh
      sub-&gt;useSharedVertices = true;
      sub-&gt;indexData-&gt;indexBuffer = ibuf;
      sub-&gt;indexData-&gt;indexCount = ibufCount;
      sub-&gt;indexData-&gt;indexStart = 0;
  
      /// Set bounding information (for culling)
      msh-&gt;_setBounds(Ogre::AxisAlignedBox(-5000,-5000,-5000,5000,5000,5000));
      //msh-&gt;_setBoundingSphereRadius(Ogre::Math::Sqrt(3*100*100));
  
      /// Notify -Mesh object that it has been loaded
      msh-&gt;load();
  
  }
  </code></pre>
  
  <p>I initialise the mesh and load it as follows </p>
  
  <pre><code>Ogre::Entity* thisEntity = mSceneMgr-&gt;createEntity("cc", "TerrainTest", "General");
  thisEntity-&gt;setMaterialName("Examples/Rockwall");
  Ogre::SceneNode* thisSceneNode = mSceneMgr-&gt;getRootSceneNode()-&gt;createChildSceneNode();
  thisSceneNode-&gt;setPosition(0, 0, 0);
  thisSceneNode-&gt;attachObject(thisEntity);
  </code></pre>
  
  <p>Any insight would be greatly appreciated.</p>