Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. need help in QSGGeometry

need help in QSGGeometry

Scheduled Pinned Locked Moved Mobile and Embedded
2 Posts 1 Posters 935 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    literA2
    wrote on last edited by p3c0
    #1

    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:

    QSGNode *TabBar::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *)
    {
        QSGNode *root = static_cast<QSGNode *>(oldNode);
        if(!root) root = new QSGNode;
        root->removeAllChildNodes();
    
        QSGGeometry *geometry;
    
        geometry = new QSGGeometry(QSGGeometry::defaultAttributes_Point2D(), 6);
        geometry->setDrawingMode(GL_TRIANGLE_FAN);
        geometry->vertexDataAsPoint2D()[0].set(20, 40);
        geometry->vertexDataAsPoint2D()[1].set(0, 0);
        geometry->vertexDataAsPoint2D()[2].set(100, 0);
        geometry->vertexDataAsPoint2D()[3].set(120, 40);
        geometry->vertexDataAsPoint2D()[4].set(100, 80);
        geometry->vertexDataAsPoint2D()[5].set(0, 80);
        node = drawPolygon(geometry, Qt::red);
        root->appendChildNode(node);
    }
    QSGNode *TabBar::drawPolygon(QSGGeometry *geometry, const QColor &color)
    {
        QSGFlatColorMaterial *material = new QSGFlatColorMaterial;
        material->setColor(color);
    
        QSGGeometryNode *node = new QSGGeometryNode;
        node->setGeometry(geometry);
        node->setFlag(QSGNode::OwnsGeometry);
        node->setMaterial(material);
        node->setFlag(QSGNode::OwnsMaterial);
        return node;
    }
    

    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.

    1 Reply Last reply
    0
    • L Offline
      L Offline
      literA2
      wrote on last edited by literA2
      #2

      update:

      Found this thread that there is no available text/glyph node yet for text rendering on the scene graph node.

      http://comments.gmane.org/gmane.comp.lib.qt.user/13735

      It was suggested (but not ideal) to draw text using QPainter on QImage and show on texture.
      Any advise how to convert the image into texture? I can't find any example. Thanks.

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved