is there other ways to handle text than jit.gl.text?

SallySel's icon

SallySel

9月 05 2023 | 10:07 午前

Dear Jitter forum

I'm working on patch in Jitter containing a lot of text content. Right now I'm using Jit.gl.text but i want to change some font and colour for individual characters within a sentence.

I know it's possible when using jit.lcd, but then i would have to rebuild the whole thing from the bottom. Maybe it would possible to sort of print the jit.gl.text output onto some texture, but i wouldn't know how to do that... Any option possible is in my interests, and help is very much needed:) Thanks

TFL's icon

TFL

9月 05 2023 | 10:46 午前

i want to change some font and colour for individual characters within a sentence.

I believe the new [jit.gl.textmult] is made for this purpose. Think of it as a [jit.gl.multiple] object, but for letters/words. [jit.gl.textmult] is actually a patcher encapsulating a js file and other objects, and looking into it, you can apparently address different font, color (or other basic gl3 parameters such as scale, position, rotation...) to individual letters/words.
This said, the object is not deeply documented and the helpfile does not seem to work. Good luck :)

TFL's icon

TFL

9月 05 2023 | 11:27 午前

I looked into the [jit.gl.textmult] helpfile and I managed to fix it (see patch below). The problem is that the input matrix does not match the order of the defined arguments. There definitely is some bug into the [jit.gl.textmult] object, I guess regarding how it handles its arguments. Maybe @federico-amazingmaxstuff or @Rob Ramirez should look into it!

But now that I'm a but more familiar with this object, I'm not sure that you can set different fonts for each text instance.

EDIT: it does work! Just send a list of all the fonts you want prepended with the word "font", Such as: {font Arial "Comic Sans MS" Georgia} without the brackets. Then you need to re-send your text. The first word will be in Arial, second in Comic Sans, third in Georgia, fourth in Arial, and so on.

Max Patch
Copy patch and select New From Clipboard in Max.

Robert Ramirez's icon

Robert Ramirez

9月 05 2023 | 6:48 午後

we welcome bug reports and feature requests for textmult at the usual place

SallySel's icon

SallySel

9月 06 2023 | 8:42 午前

Hey TFL
Thank you so much for the reply. I only scratched the surface of it, but I can see that Jit.gl.textmult is really powerfull. I'm wondering if it's only working in 3D mode or is a there 2D option that i'm not able to find? The project I'm working contains a lot of words that is getting generated each second, and I dont think my mac would be able to handle all this in 3D.

I've attached a screenshot so you can get an idea of the purpose and I'm looking for a solution that can highlight some single words.

Dont know if that makes sense?

TFL's icon

TFL

9月 06 2023 | 11:55 午前

Thanks Rob, I submitted a request for the bug.

Sallysel:
About the 2D mode:
[jit.gl.textmult] is built around the regular [jit.gl.text] object (basically, [jit.gl.textmult] programmatically instanciates multiple [jit.gl.text] - you can find that logic in the js file found inside of [jit.gl.textmult]), so it could theoritically be possible to make it work in 2D mode (as there is one for [jit.gl.text]), but it's not the case yet.
I tried to modify the js file to simply force 2d mode of every [jit.gl.text] object it instanciates, but it does not work as is, so more modifications should be done. Maybe you can send a feature request as Rob suggested.

This said, the depth attribute does work, so you can send "depth 0" to [jit.gl.textmult] to get your text flat (but they're still 3D shapes though). You need to rebang the color matrix after that...

About lot of words getting generated each second:
First, [jit.gl.textmult] takes a lot of time to process a new list of words, so don't think about submitting a new list every second. If you already know every word that you will eventually display, you should better send all of them first, then hide the ones you don't want by shifting their position away from the camera. It is not trivial to do and require some basic matrix manipulation but it's doable.
It would be more simple and efficient to be able to control the "enable" attribute of each jit.gl.text, but it is not a feature of jit.gl.textmult yet. You can ask for it too!

If you don't know in advance every generated words, I think you should better kind of recreate your own [jit.gl.textmult] so that you can programmatically create new [jit.gl.text] without having to reinstanciate the old ones.

SallySel's icon

SallySel

9月 07 2023 | 10:55 午前

Hello again TFL

Thanks for an extremely helpful reply! I can tell that [jit.gl.textmult] have a hard time handling all that information, since i don't know the words in advance. Sadly, my Java skills are limited, so I may consider submitting a feature request for either jit.gl.text or jit.gl.textmult. However, upon a quick look at the jit.gl.textmult script , it appears that it may serve a different purpose.

I'll get back when/if i find a suitable solution! Maybe with jit.lcd...

Again thanks a lot blessed one!

TFL's icon

TFL

9月 08 2023 | 6:28 午後

Two things to say:

First, I was wrong when I said earlier that the helpfile for jit.gl.textmult was not working. In fact it was not working for me, as it appears to be a bug with only some GPUs (in my case the integrated graphics Intel UHD 630). I relaunched Max with the dedicated GPU, and tried on another computer with another GPU, and the helpfile works as expected with those, so sorry if that misleaded you as you most certainly did not encounter that issue! I submitted the issue and it's being investigated.

Then:

However, upon a quick look at the jit.gl.textmult script , it appears that it may serve a different purpose.

I am not so sure. Here are some heavily truncated extracts from multiple_text.js found inside of [jit.gl.textmult], with some extra comments I added:

function TextObj() 
{   
    this.glText = new JitterObject("jit.gl.text"); //THIS LINE CREATES A NEW JIT.GL.TEXT
    //[...]
}
//[...]
function SetTextAndDrawBang() //THIS FUNCTION IS CALLED WHENEVER A NEW TEXT IS RECEIVED
{   
    //[...]
    if (Array.isArray(g_text)) {
        //[...]
        for (var i=0; i<g_text.length; i++) { 
            //[...]
            CreateTextObjs(); //THIS FUNCTION (DETAILED BELOW) IS CALLED FOR EACH ELEMENT OF TEXT (ie each element of the array g_text)
            //[...]
            g_textObj.SetText(g_text[i]);
            g_textObj.Draw();
            g_wordIndex++;
        }
    //[...]
}
//[...]

function SetAllTextAttributes()
{   
    if (g_textObj != null) {
        g_textObj.SetMode(mode); // THIS MIGHT BE WHERE YOU CAN MANUALLY SET THE MODE TO "2d"
        // g_textObj.SetFont(font);
        g_textObj.SetDepth(depth)
        g_textObj.SetWeight(weight);
        g_textObj.SetAlign(align);
    }

} 

function CreateTextObjs()
{    
    if (g_textObj == null) {
        g_textObj = new TextObj(); // IT CALLS TextObj() (see at the top) WHICH CREATES A NEW JIT.GL.TEXT
        SetAllTextAttributes();
    }
}

So yes, that js file indeed creates a new [jit.gl.text] for each element of text.

There is also a lot of code that deals with the control matrices (for position, scale, color...), but I'm still struggling to get what's going on, and what makes the 2d mode to not work. But that problem hooked I guess so I might investigate a bit further.

Your specific case would require a lot of work to modify the existing [jit.gl.textmult] that would allow you to first instanciate a given number of [jit.gl.text], even with empty text, then dynamically populate them individually with your text as it comes. It should make the generation much faster.