need help in 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:
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.
-
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.