title: Draw triangle with Qt3D
body: <p>I need to draw a polygon with Qt3D, but i found how i can do this with triangles. So. I found a code, that works more tightly with OpenGL from Qt3D. It was drawing the line but i changed one to draw triangles. When i set <code>setPrimitiveType(Qt3DRender::QGeometryRenderer::TriangleStrip);</code>, then it works. But i wanna use 
  <code>setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles);</code>, that don't work for some reason and don't draw anything. Maybe i did wrong configuration of vertex and index attributes? Or maybe i use incorrect input? (Example of my input is in the bottom)</p>
  
  <pre><code>void MainWindow::drawTriangles(const QPolygonF polygon, QColor color, Qt3DCore::QEntity *_rootEntity)
  {
      int numOfVertices = polygon.size();
      auto *geometry = new Qt3DRender::QGeometry(_rootEntity);
  
      // Create and fill vertex buffer
      QByteArray bufferBytes;
      bufferBytes.resize(3 * numOfVertices * static_cast&lt;int&gt;(sizeof(float)));
      float *positions = reinterpret_cast&lt;float*&gt;(bufferBytes.data());
  
      for(auto point : polygon){
          float fHalfMapWidth = (dFittedMaxMapX_ - dFittedMinMapX_) / 2;
          float fHalfMapHeight = (dFittedMaxMapY_ - dFittedMinMapY_) / 2;
  
          *positions++ = static_cast&lt;float&gt;(point.x() - (dFittedMinMapX_ + fHalfMapWidth));
          *positions++ = 0.0f; //We need to drow only on the surface
          *positions++ = static_cast&lt;float&gt;(point.y() - (dFittedMinMapY_ + fHalfMapHeight));
      }
  
      auto *buf = new Qt3DRender::QBuffer(geometry);
      buf-&gt;setData(bufferBytes);
  
      auto *positionAttribute = new Qt3DRender::QAttribute(geometry); // Create a vertex attribute
      positionAttribute-&gt;setName(Qt3DRender::QAttribute::defaultPositionAttributeName());
      positionAttribute-&gt;setVertexBaseType(Qt3DRender::QAttribute::Float); // In vertex buffer we store floats
      positionAttribute-&gt;setVertexSize(3); // Size of a vertex
      positionAttribute-&gt;setAttributeType(Qt3DRender::QAttribute::VertexAttribute); // Type of an attribute
      positionAttribute-&gt;setBuffer(buf); // Set vertex buffer
      positionAttribute-&gt;setByteStride(3 * sizeof(float)); // Stride between vertices
      geometry-&gt;addAttribute(positionAttribute); // Add the attribute in our  Qt3DRender::QGeometry
  
      // Create and fill an index buffer
      QByteArray indexBytes;
      indexBytes.resize(numOfVertices * static_cast&lt;int&gt;(sizeof(unsigned int))); // start to end
      unsigned int *indices = reinterpret_cast&lt;unsigned int*&gt;(indexBytes.data());
      for(unsigned int i = 0; i &lt; static_cast&lt;unsigned int&gt;(numOfVertices); ++i) {
          *indices++ = i;
      }
  
      auto *indexBuffer = new Qt3DRender::QBuffer(geometry);
      indexBuffer-&gt;setData(indexBytes);
  
      auto *indexAttribute = new Qt3DRender::QAttribute(geometry); // Create an index attribute
      indexAttribute-&gt;setVertexBaseType(Qt3DRender::QAttribute::UnsignedInt); // In the index buffer we will store Unsigned int
      indexAttribute-&gt;setAttributeType(Qt3DRender::QAttribute::IndexAttribute); // Type of an attribute
      indexAttribute-&gt;setBuffer(indexBuffer); // Set the index buffer
      indexAttribute-&gt;setCount(static_cast&lt;unsigned int&gt;(numOfVertices)); // As i understand, this is a number of vertices
      geometry-&gt;addAttribute(indexAttribute); // Add attribute in our Qt3DRender::QGeometry
  
  
      auto *poly = new Qt3DRender::QGeometryRenderer(_rootEntity);
      poly-&gt;setGeometry(geometry); 
      //poly-&gt;setPrimitiveType(Qt3DRender::QGeometryRenderer::TriangleStrip); - Working variant
      poly-&gt;setPrimitiveType(Qt3DRender::QGeometryRenderer::Triangles); // - This is not working variant
  
      //Create a material
      auto *material = new Qt3DExtras::QPhongMaterial(_rootEntity);
      material-&gt;setAmbient(color);
  
      auto *trianglesEntity = new Qt3DCore::QEntity(_rootEntity);
      trianglesEntity-&gt;addComponent(poly); // Add our primitives
      trianglesEntity-&gt;addComponent(material); // Add material
  }
  </code></pre>
  
  <p>I tried to use three and four points. When i use 4 points, then it draws if i set primitive type to "TriangleStrip". But with "Triangles" It's don't work in both cases.</p>
  
  <pre><code>mapBorder &lt;&lt; QPointF(300,200) &lt;&lt; QPointF(100,200) &lt;&lt; QPointF(200,0) &lt;&lt; QPointF(300,200) &lt;&lt; QPointF(200,0) &lt;&lt; QPointF(500,200) &lt;&lt; QPointF(500,300); 
  drawTriangles(mapBorder, QColor(Qt::black), mapEntity_);
  </code></pre>
  
  <p>Or can you to give me another suggestion how to draw polygon or triangle.</p>