Board index FlightGear Development Canvas

Rendering just text onto existing texture  Topic is solved

Canvas is FlightGear's new fully scriptable 2D drawing system that will allow you to easily create new instruments, HUDs and even GUI dialogs and custom GUI widgets, without having to write C++ code and without having to rebuild FlightGear.

Rendering just text onto existing texture

Postby benih » Thu Nov 12, 2020 1:58 pm

Hello,
some time ago, i converted the Davtron clock in the C182S torender its text via canvas.
This works nicely; however, i had to replace the entire texture of the instrument with the canvas rendered one containing the text.

Is it already possible with 2020.3 (or later) to render just transparent text and apply it ontop an existing texture?
If not, is there a best practice approach how to do that with other techniques?

(This would also be very cool to be able to switch the registration implementation on the fuselage to canvas, which is the underlying idea of this post)
User avatar
benih
 
Posts: 1689
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Rendering just text onto existing texture

Postby Hooray » Mon Nov 16, 2020 8:36 pm

The osgtext issue is a long-standing problem: http://wiki.flightgear.org/OSGText_Issues

What you have done is the recommended fix, i.e. porting features to use the Canvas instead.

However, I think you should be able to merge multiple textures using the Canvas system if that works for you ?

There are actually multiple pathways here.
For instance, you could add Canvas.Image child nodes to your canvas to emulate multi-texturing and then play with the z-index/alpha settings as needed, possibly in conjunction with custom effects.
You could also set up a transparent Canvas. People have used this approach to implement dynamic liveries: http://wiki.flightgear.org/Howto:Dynami ... via_Canvas

Other than that, having a built-in mechanism to let legacy features use a canvas fallback is also a long-standing idea.

Specifically, there have been talks to create a Canvas based back-end for the HUD and 2D panels module, as well as experimental work to render PUI/XML dialogs via Canvas.
The HUD/2D panels efforts are actively being pursued at the moment: http://wiki.flightgear.org/Post_FlightG ... ges#Canvas


The long term idea being to help unify the 2D rendering back-end so that a more recent version OpenGL (GLES/Core profile) can be used by FlightGear.
And maybe some day, only use OSG so that VSG can be adopted more easily.

http://wiki.flightgear.org/Unifying_the ... via_canvas
http://wiki.flightgear.org/FlightGear_and_OpenGL_ES


If in doubt, feel free to reach out to the devel mailing list
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Rendering just text onto existing texture

Postby benih » Tue Nov 17, 2020 5:28 pm

I got some quick and dirty code working, i can show a canvas window with the registration added as an text.
Whats missing is to display it on the fuselage.

From the examples i think this must read "liveryCanvas.addPlacement({"node": "Fuselage.001"});" because the blender model has the mesh called like this.
However nothing draws (despite the property tree says "OK" for the placement status!).
When i redirect it to the davtron clock lcd surface, it shows instead of the clock, so basicly its working.
What could be wrong here?

Code: Select all
var liveryCanvas = canvas.new({
    "name": "liveryCustomRegistration",   # The name is optional but allow for easier identification
    "size": [4528, 2264], # Size of the underlying texture (should be a power of 2, required) [Resolution]
    "view": [4528, 2264], # Virtual resolution (Defines the coordinate system of the canvas [Dimensions]
                          # which will be stretched the size of the texture, required)
    "mipmapping": 1       # Enable mipmapping (optional)
});


var bggroup       = liveryCanvas.createGroup();
var fuselagegroup = liveryCanvas.createGroup();

# load original livery image file as background
var livery_prop = props.globals.getNode("sim/model/livery/name");
var livery_idx  = props.globals.getNode("sim/model/livery/index");
var livery_txtr = props.globals.getNode("sim/model/livery/texture");

print("LIVERY-DBG");
debug.dump(livery_prop);
debug.dump(livery_idx);
debug.dump(livery_txtr);

bggroup.createChild("image")
        .setFile("Models/" ~ livery_txtr.getValue())
        .setSize(4528,2264)
        .setTranslation(0, 0);

# Create text elements
var canvas_immat_left = fuselagegroup.createChild("text", "fuselage.immat.left")
                .setTranslation(1500, 800)      # The origin is in the top left corner
                .setAlignment("center-center"); # All values from osgText are supported (see $FG_ROOT/Docs/README.osgtext)


liveryCanvas.addPlacement({"node": "Fuselage.001"});

# Debug window
var window = canvas.Window.new([566,283],"dialog");
window.setCanvas(liveryCanvas);


# Update registration display
var set_registration_number = func (namespace, immat) {
    if (immat == nil)
        return;

    print("c182 set_registration_number");
    var livery_font = namespace.getNode("sim/model/livery/immat_font",1).getValue();  # to be defined from livery xml
    var livery_size = namespace.getNode("sim/model/livery/immat_size",1).getValue();
    var livery_font_r = namespace.getNode("sim/model/livery/immat_r",1).getValue();
    var livery_font_g = namespace.getNode("sim/model/livery/immat_g",1).getValue();
    var livery_font_b = namespace.getNode("sim/model/livery/immat_b",1).getValue();
    debug.dump(namespace);
    debug.dump(immat);
    debug.dump(livery_font);

    canvas_immat_left.setText(immat)
        .setRotation(0,50)
        .setFont(livery_font) # Fonts are loaded either from $AIRCRAFT_DIR/Fonts or $FG_ROOT/Fonts
        .setFontSize(livery_size, 1.0)       # Set fontsize and optionally character aspect ratio
        .setColor(livery_font_r,livery_font_g,livery_font_b)           # Text color
        .setText(immat);


    # show/hide registration on fuselage
    canvas_immat_left.show();

};
User avatar
benih
 
Posts: 1689
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Rendering just text onto existing texture

Postby cgdae » Tue Nov 17, 2020 5:45 pm

At the hackthon we tried to apply a Canvas View as a texture to a fuselage but couldn't get it to work.

Applying to an existing surface eventually worked, but we had to change the surface to use *emis 1 1 1* in order to show up, and make sure that the texture coordinates for each of the surface's vertices were set appropriately (e.g. not all *0 0*).

For details, please see: http://wiki.flightgear.org/Hackathon_Pr ... and_Canvas

Of course it's entirely possible that our use of a texture from a camera will have been extra- picky.

Hope that's of some use.

- Jules
cgdae
 
Posts: 117
Joined: Tue May 31, 2016 8:35 pm

Re: Rendering just text onto existing texture

Postby Hooray » Tue Nov 17, 2020 6:11 pm

That should actually work, here's the original screen shot showing how an animated Canvas is placed onto the face of the ogeL pilot - i.e. showing a moving map:

Image

PS: You need a UV-mapped surface and use the object's ID for the placement so that the texture visitor can replace the static texture with the canvas one
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Rendering just text onto existing texture

Postby benih » Tue Nov 17, 2020 6:15 pm

It is uv mapped, however my approach does not work...
It must be somewhere with applying, because applying it to some other Surface does work.
User avatar
benih
 
Posts: 1689
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Rendering just text onto existing texture

Postby benih » Tue Nov 17, 2020 6:27 pm

An idea stroke my mind.
I will try to add simple 2d surfaces for the immat locations and render text onto them; basicly the current implementation does the same anyways.
This way i can leave the underlaying livery alone.
Will report back if this is more easy
User avatar
benih
 
Posts: 1689
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Rendering just text onto existing texture

Postby benih » Wed Nov 18, 2020 11:50 am

I succeeded in trying that out, and principially, it's easy.

However, there is still a problem, the rendered texture is horribly distorted when viewed on the immat pane.
The reason is surely some blender materials/texture stuff which is way above my skill set... :(

After that there is still the problem on how to show the canvas on the Multiplayer instance. I've got untested code for that already, but to be able to play with that, i need first to tackle the texture distortion problem.
User avatar
benih
 
Posts: 1689
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Rendering just text onto existing texture  

Postby benih » Thu Nov 19, 2020 4:37 pm

OK, got it: it was indeed the UV-map that i forgot to remap to the new vertex size.
User avatar
benih
 
Posts: 1689
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit

Re: Rendering just text onto existing texture

Postby Hooray » Sun Nov 22, 2020 1:58 pm

If you can think of any improvements to the docs, you should consider getting involved in updating those according to your own experiences.
Please don't send support requests by PM, instead post your questions on the forum so that all users can contribute and benefit
Thanks & all the best,
Hooray
Help write next month's newsletter !
pui2canvas | MapStructure | Canvas Development | Programming resources
Hooray
 
Posts: 12707
Joined: Tue Mar 25, 2008 9:40 am
Pronouns: THOU

Re: Rendering just text onto existing texture

Postby benih » Sun Nov 22, 2020 5:27 pm

I think the docs are fine, especially on how to put the texture into scenery objects.
I just was not bright enough to put it to action :P
User avatar
benih
 
Posts: 1689
Joined: Tue Aug 15, 2017 10:34 am
Callsign: D-EBHX
Version: next
OS: Debian Linux 64bit


Return to Canvas

Who is online

Users browsing this forum: No registered users and 3 guests