Results 1 to 17 of 17

Thread: help on QSGGeometry

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Oct 2014
    Posts
    104
    Thanks
    16
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11 Windows

    Default help on QSGGeometry

    Hi,

    I would like to know some advise on creating a custom geometry using scene graph.
    My problem is I don't know how to fill the custom geometry with color.
    And how to add text on geometry node without using QPainter, is it possible?

    Below is my code:

    Qt Code:
    1. QSGNode *TabBar::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
    2. {
    3. QSGNode *root = static_cast<QSGNode *>(oldNode);
    4. if(!root) root = new QSGNode;
    5. root->removeAllChildNodes();
    6.  
    7. QSGGeometry *geometry;
    8.  
    9. geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 6);
    10. geometry->setDrawingMode(GL_TRIANGLE_FAN);
    11. geometry->vertexDataAsPoint2D()[0].set(20, 40);
    12. geometry->vertexDataAsPoint2D()[1].set(0, 0);
    13. geometry->vertexDataAsPoint2D()[2].set(100, 0);
    14. geometry->vertexDataAsPoint2D()[3].set(120, 40);
    15. geometry->vertexDataAsPoint2D()[4].set(100, 80);
    16. geometry->vertexDataAsPoint2D()[5].set(0, 80);
    17. node = drawPolygon(geometry, Qt::red);
    18. root->appendChildNode(node);
    19. }
    20. QSGNode *TabBar::drawPolygon(QSGGeometry *geometry, const QColor &color)
    21. {
    22. QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
    23. material->setColor(color);
    24.  
    25. QSGGeometryNode *node = new QSGGeometryNode;
    26. node->setGeometry(geometry);
    27. node->setFlag(QSGNode::OwnsGeometry);
    28. node->setMaterial(material);
    29. node->setFlag(QSGNode::OwnsMaterial);
    30. return node;
    31. }
    To copy to clipboard, switch view to plain text mode 

    Update:
    I managed to fill the geometry using GL_TRIANGLE_FAN drawingMode and by modifying the vertices which will start on the vertex which will create a triangle without intersecting each other.

    The problem now is how to draw a text on the geometry.

    Please advise. TIA.
    Last edited by joko; 2nd April 2015 at 16:35.

Similar Threads

  1. Need help with two questions please
    By phantom2323 in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2012, 11:33
  2. Qt like VS add-in questions
    By GreenScape in forum General Programming
    Replies: 0
    Last Post: 4th August 2010, 09:28
  3. Sql questions
    By Nb2Qt in forum Qt Programming
    Replies: 4
    Last Post: 15th February 2007, 22:53

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.