[Interest] How to use QSGSimpleTextureNode?

Gunnar Sletta gunnar at sletta.org
Mon Nov 3 22:11:26 CET 2014


On 03 Nov 2014, at 17:15, Nuno Santos <nunosantos at imaginando.pt> wrote:

> Hi,
> 
> I’m trying to render text on scene graph. My strategy consists in creating a texture with all the glyphs and then draw a specific subset of the texture for each glyph. I have already done this for iOS and Android native API’s but now, i’m porting my app to Qt/Qml and need to do it on scene graph.

If you already have working GL code, then maybe QQuickWindow::beforeRendering() is a more straightforward way to get this working? You only need to go through scene graph API if you want this to interact with a QML UI.

> 
> My new node is extending QSGSimpleTextureNode. The code below is just for the most basic test purpose. 

QSGSimpleTextureNode only supports drawing a textured quad. If you want to draw a bunch of glyphs on one node (like a word or a sentence), you probably want to use a QSGGeomtryNode with TexturedPoint2D as attribute set combined with a QSGTextureMaterial.

> 
> unsigned char *data = (unsigned char*) malloc(ts*ts*4);
> uint8_t * p = data;
> 
> for(int i=0; i<ts*ts; ++i)
> {
>    *p = 0; ++p;
>    *p = 255; ++p;
>    *p = 255; ++p;
>    *p = 0; ++p;
> }
> 
> glGenTextures(1, &_texture);
> 
> glBindTexture(GL_TEXTURE_2D, _texture);
> 
> glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
> glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
> glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ts, ts, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);

You create QSGTexture instances from a GL texture id with QQuickWindow::createTextureFromId(). If your texture has special needs, you can also subclass QSGTexture and reimplement the pure virtuals.

> 
> // how do I set data to the texture?
> setTexture()
> 
> free(data);
> 
> The essential question right now is how do I set my custom texture data to a texture? 
> 
> I have a Googled a lot about QSGSimpleTextureNode and QSGTexture but couldn’t find any clear example on how to do this.
> 
> Any thoughts?

There are several examples that show how the scene graph APIs work in the qtdeclarative/examples/quick/scenegraph folder. That is the place to start.

cheers,
Gunnar

> 
> Thanks,
> 
> Nuno Santos
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest




More information about the Interest mailing list