How to use QSGSimpleTextureNode?
I am trying to figure out how to use QSGSimpleTextureNode, but the Qt documentation is very vague. I want to render text on a scene graph, so basically I want to draw a texture with all the glyphs and then set that texture to a QSGSimpleTextureNode. My idea was to create a texture using standard OpenGL code and set the texture data to the data just created. I cannot find an example to show me how to achieve this.
+3
source to share
1 answer
I would use QSGGeometryNode instead of QSGSimpleTextureNode. If I am not mistaken, it is not possible to set texture coordinates in QSGSimpleTextureNode. You can write your own QQuickItem for SpriteText and override updatePaintNode:
QSGNode* SpriteText::updatePaintNode(QSGNode *old, UpdatePaintNodeData *data)
{
QSGGeometryNode* node = static_cast<QSGGeometryNode*>(old);
if (!node){
node = new QSGGeometryNode();
}
QSGGeometry *geometry = NULL;
if (!old){
geometry = new QSGGeometry(QSGGeometry::defaultAttributes_TexturedPoint2D()
,vertexCount);
node->setFlag(QSGNode::OwnsGeometry);
node->setMaterial(material); // <-- Texture with your glyphs
node->setFlag(QSGNode::OwnsMaterial);
geometry->setDrawingMode(GL_TRIANGLES);
node->setGeometry(geometry);
} else {
geometry = node->geometry();
geometry->allocate(vertexCount);
}
if (textChanged){
//For every Glyph in Text:
//Calc x + y position for glyph in texture (between 0-1)
//Create vertexes with calculated texture coordinates and calculated x coordinate
geometry->vertexDataAsTexturedPoint2D()[index].set(...);
...
node->markDirty(QSGNode::DirtyGeometry);
}
//you could start timer here which call update() methode
return node;
}
+2
source to share