Board index FlightGear Development Canvas

Canvas HUD - Target Markers

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.

Canvas HUD - Target Markers

Postby SplitDecision » Thu Oct 26, 2017 7:22 am

Hi,

I'm trying to create a canvas HUD I can add over the existing non canvas HUD in the A-4K which will serve one purpose, to track targets (e.g. multiplayer or AI aircraft). The reason for this is that the target markers feature of the non canvas HUD doesn't work in newer versions of FG anymore. I am currently trying to get canvas to work before I start creating this (as I am completely new to canvas development). I have followed the wiki article http://wiki.flightgear.org/Howto:Add_a_2D_canvas_instrument_to_your_aircraft and created the following in order to simply display some text on the HUD glass to test it out.

Code: Select all
var my_canvas = canvas.new({
  "name": "hud-glass",   
  "size": [4,4],         
  "view": [768, 1024],
  "mipmapping": 1       
});

my_canvas.addPlacement({"node": "hud-glass"});

var group = my_canvas.createGroup();

var text = group.createChild("text", "optional-id-for element")
                .setTranslation(10,20)                     
                .setAlignment("left-center")
                .setFont("LiberationFonts/LiberationSans-Regular.ttf")                 
                .setFontSize(14,1.2)                       
                .setColor(2,0,0)     
                .setText("This is a text element");
text.hide();
text.setText("Hello!").show();


Problem is, the text isn't showing. I've checked the console when I run FG and no errors associated with this come up. The hud-glass placement is referring to the model I added to the cockpit in A-4K/Models/Cockpit.xml which is textured but somewhat transparent. I have also referred to the above code nasal file in the set.xml
Any help would be much appreciated. Especially if someone could grab some code for the target tracking in a canvas HUD which should work when I add it. I understand I might have to make a .svg file for this to work as well?

Thanks
Developing the RNZAF A4K Skyhawk for FlightGear. Download: https://github.com/FGMEMBERS/A-4K
User avatar
SplitDecision
 
Posts: 113
Joined: Sat May 23, 2015 5:54 am
Location: New Zealand
Callsign: SplitDec, NZStrik
OS: Windows 10

Re: Canvas HUD - Target Markers

Postby PINTO » Thu Oct 26, 2017 8:01 am

Try making your size (much) bigger. 768,1024 is good. Also, add in a my_canvas.setColorBackground(0,0,0,0); somewhere in there.

Canvas will wipe out any texture you have assigned.

I used

Code: Select all
var my_canvas = canvas.new({
  "name": "hud-glass",   
  "size": [1024, 1024],         
  "view": [1024, 1024],
  "mipmapping": 1       
});
my_canvas.setColorBackground(0,0,0,0);
my_canvas.addPlacement({"node": "hud-glass"});

var group = my_canvas.createGroup();

var text = group.createChild("text", "optional-id-for element")
                .setTranslation(500,500)                     
                .setAlignment("left-center")
                .setFont("LiberationFonts/LiberationSans-Regular.ttf")                 
                .setFontSize(56,1.2)                       
                .setColor(1,1,1)     
                .setText("This is a text element");
text.hide();
text.setText("Hello!").show();


(note the bigger font size and the setColor - the values should be between 0 and 1)

The result is this:

Image

As far as tracking targets, I'd encourage you to look into radar-logic.nas found here: https://github.com/NikolaiVChr/flightgear-saab-ja-37-viggen/blob/master/Aircraft/JA37/Nasal/radar-logic.nas - it's probably the most realistic radar script we have in FG right now. In your canvas code, you can then iterate over radar_logic.tracks to see valid contacts, and use .get_cartesian() to map them to the HUD (check out this little bit of code for how the viggen does it). Also, if you plan on dropping ordinance using any kind of guidance, using guided-missiles.nas will help a lot, the radar-logic script will be a HUGE help as it ties in directly.
Actively developing the MiG-21bis (github repo) (forum thread) (dev discord) (fg wiki)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 966
Joined: Wed Oct 21, 2015 7:28 pm
Callsign: pinto
Version: stable
OS: Win10

Re: Canvas HUD - Target Markers

Postby SplitDecision » Thu Oct 26, 2017 9:04 pm

Thanks for your help,

I've tried the code above, but unfortunately its still not working. I increased the font size as well but still nothing.

Does it mater if the HUD glass has some transparency in the model itself? I noticed that some developers add a line of code to make the model transparent rather than doing it in blender etc.
Also, does it matter where the model is located e.g. in A-4K/Models/Cockpit/Instruments/HUD ?
Developing the RNZAF A4K Skyhawk for FlightGear. Download: https://github.com/FGMEMBERS/A-4K
User avatar
SplitDecision
 
Posts: 113
Joined: Sat May 23, 2015 5:54 am
Location: New Zealand
Callsign: SplitDec, NZStrik
OS: Windows 10

Re: Canvas HUD - Target Markers

Postby Necolatis » Fri Oct 27, 2017 12:49 am

In my experience this is not enough:

my_canvas.addPlacement({"node": "hud-glass"});

Some things u ought to make sure:
1 - The object MUST be UV mapped.
2 - The object MUST have a texture already that you want to replace with canvas.
3 - Best is to specify the texture also when you do addPlacement: my_canvas.addPlacement({"node": "hud-glass", "texture": "hud-glass.png});
"Airplane travel is nature's way of making you look like your passport photo."
— Al Gore
User avatar
Necolatis
 
Posts: 2233
Joined: Mon Oct 29, 2012 1:40 am
Location: EKOD
Callsign: Leto
IRC name: Neco
Version: 2020.3.19
OS: Windows 10

Re: Canvas HUD - Target Markers

Postby PINTO » Fri Oct 27, 2017 5:58 pm

Tbh I think (at least for me personally) it'd be hard to debug without access to your code and models.
Actively developing the MiG-21bis (github repo) (forum thread) (dev discord) (fg wiki)

http://opredflag.com is an active flightgear dogfighting community (using a system that isn’t bombable)
User avatar
PINTO
 
Posts: 966
Joined: Wed Oct 21, 2015 7:28 pm
Callsign: pinto
Version: stable
OS: Win10

Re: Canvas HUD - Target Markers

Postby Thorsten » Sat Oct 28, 2017 9:08 am

I hate to point out the obvious, but first rule of development if you don't understand the tools completely:

Do not attempt to write anything from scratch - copy/paste an existing example, make sure it runs, then adapt to your needs, checking each step.

There's about a dozen things you could have done wrong in the process of writing from scratch.

The above is a corollary of the basic principle that running code is always much easier to debug than non-functioning code.

I'm trying to create a canvas HUD I can add over the existing non canvas HUD in the A-4K


Dependent on how you do this, this opens up the possibility of all sorts of lovely z-ordering issues - a wrongly declared inner glass surface can hide the outer surface. Unless you're very experienced in setting effect parameters, this is probably a bad idea to begin with.
Thorsten
 
Posts: 12490
Joined: Mon Nov 02, 2009 9:33 am

Re: Canvas HUD - Target Markers

Postby SplitDecision » Sat Oct 28, 2017 9:39 am

Hi, yeah I didn't write it from scratch, used the code off the wiki on creating a 2d canvas instrument. Unfortunately something else went wrong which I am yet to identify (probably to do with the model).
Developing the RNZAF A4K Skyhawk for FlightGear. Download: https://github.com/FGMEMBERS/A-4K
User avatar
SplitDecision
 
Posts: 113
Joined: Sat May 23, 2015 5:54 am
Location: New Zealand
Callsign: SplitDec, NZStrik
OS: Windows 10

Re: Canvas HUD - Target Markers

Postby Alant » Sat Oct 28, 2017 2:09 pm

For a very simple canvas hud look at the Buccaneer in fgaddon. It contains jlittle more than a target marker.. Cut and paste the following files as a start point.Search the rest of the Buccaneer for any files which refer to these files and you will see how to add the HUD to an existing aircraft.
Buccaneer/Instruments/Canvas-HUD.ac, Canvas-HUD.xml, Canvas -screen.png, and Buccaneer/Systems/canvas-HUD.nas
Alan
Alant
 
Posts: 1219
Joined: Wed Jun 23, 2010 6:58 am
Location: Portugal
Callsign: Tarnish99
Version: latest Git
OS: Windows 10/11

Re: Canvas HUD - Target Markers

Postby Hooray » Sun Oct 29, 2017 6:39 am

You folks might want to consider turning the responses provided here into a new tutorial for the wiki ?
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: Canvas HUD - Target Markers

Postby Alant » Sun Oct 29, 2017 9:26 am

There is already one - http://wiki.flightgear.org/Canvas_HUD

Rather than starting a new one, this should be improved.
Alant
 
Posts: 1219
Joined: Wed Jun 23, 2010 6:58 am
Location: Portugal
Callsign: Tarnish99
Version: latest Git
OS: Windows 10/11

Re: Canvas HUD - Target Markers

Postby Hooray » Sun Oct 29, 2017 4:44 pm

Yeah, I agree - good point.
I do think however, that it would make sense to encourage people to use a Canvas GUI dialog for prototyping purposes - much faster development that way, and everything else is just a canvas placement after all.
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


Return to Canvas

Who is online

Users browsing this forum: No registered users and 6 guests