Board index FlightGear Development Canvas

image only seen after FG reset  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.

image only seen after FG reset  

Postby jam007 » Wed Feb 13, 2013 8:55 pm

I have a canvas showing an image and a number of paths.
When I start FG the canvas only shows the path but not my image.
But if I reset FG (File->Reset) then the image also is shown. :?

The code
Code: Select all
# ==============================================================================
# Radar
# ==============================================================================

var radar = {
  new: func()
  {
    print("Powering up radar...");

    var m = { parents: [radar] };
   
    # create a new canvas...
    m.canvas = canvas.new({
      "name": "RADAR",
      "size": [1024, 1024],
      "view": [1024, 1024],
      "mipmapping": 1
    });
   
    # ... and place it on the object called Screen
    m.canvas.addPlacement({"node": "Screen"});
    m.canvas.setColorBackground(0.20,0.27,0.16);
    var g = m.canvas.createGroup();
    var g_tf = g.createTransform();

    m.no_stroke = 6;
    m.stroke_pos= [];
    for(var i=0; i < m.no_stroke; i = i+1) {
      append(m.stroke_pos, 0);
    }

      m.stroke = [];
      m.tfstroke=[];
      for(var i=0; i < m.no_stroke; i = i+1) {
        append(m.stroke,
         g.createChild("path")
         .moveTo(0, 120)
         .lineTo(0, 904)
         .close()
         .setStrokeLineWidth(12)
         .setColor(0.6,0.7,1.0, 1.0/(m.no_stroke-i)));
       append(m.tfstroke, m.stroke[i].createTransform());
       m.tfstroke[i].setTranslation(50, 0);
     }

    m.antennay=g.createChild("path")
                .moveTo(900, 512)
                .lineTo(920, 512)
                .close()
                .setStrokeLineWidth(18)
                .setColor(0.6,0.7,1.0, 1.0);

    m.glide=g.createChild("path")
                .moveTo(10, 1000)
                .lineTo(1000, 1000)
                .close()
                .setStrokeLineWidth(18)
                .setColor(0.96,0.74,0.20, 1.0);

    m.course=g.createChild("path")
                .moveTo(1000, 10)
                .lineTo(1000, 1000)
                .close()
                .setStrokeLineWidth(18)
                .setColor(0.96,0.74,0.20, 1.0);

    m.scale=g.createChild("image")
             .setFile("Radar/scale.png")
             .setSize(1024,1024)
             .setTranslation(0,0);

    return m;
  },

  update: func()
  {
    var pos=512+360*math.sin(getprop("sim/time/elapsed-sec")/2);
    for(var i=1; i < me.no_stroke; i = i+1) {
      me.stroke_pos[i-1]=me.stroke_pos[i];
      me.tfstroke[i-1].setTranslation(me.stroke_pos[i-1], 0);
    }
    me.stroke_pos[me.no_stroke-1] = pos;
    me.tfstroke[me.no_stroke-1].setTranslation(pos, 0);

    settimer(func me.update(), 0.05);
  },
};

setlistener("/nasal/canvas/loaded", func {
  var scope = radar.new();
  scope.update();
}, 1);
Last edited by Gijs on Wed Feb 13, 2013 8:58 pm, edited 1 time in total.
Reason: Please edit your post if you have more to add, shortly after posting.
jam007
 
Posts: 477
Joined: Sun Dec 16, 2012 10:04 am
Location: Uppsala, Sweden
Version: 2017.3.1
OS: Ubuntu 16.04

Re: image only seen after FG reset

Postby TheTom » Thu Feb 14, 2013 4:40 pm

Seems like OpenSceneGraph calculates the texture size not until first being rendered. If not manually specifying the source rectangle for the image it is assumed being 0x0 which is the cause for the image not being visible :) I've pushed a fix to SimGear which by default now always shows the full image (specified with relative coordinates). You can also achieve this manually by calling "setSourceRect(0,0,1,1)" on the image.

Nice animation btw. ;)
TheTom
 
Posts: 322
Joined: Sun Oct 09, 2011 10:20 am

Re: image only seen after FG reset

Postby jam007 » Thu Feb 14, 2013 6:13 pm

TheTom wrote in Thu Feb 14, 2013 4:40 pm: I've pushed a fix to SimGear which by default now always shows the full image (specified with relative coordinates). You can also achieve this manually by calling "setSourceRect(0,0,1,1)" on the image.

Thanks!

TheTom wrote in Thu Feb 14, 2013 4:40 pm:Nice animation btw. ;)

Thanks
jam007
 
Posts: 477
Joined: Sun Dec 16, 2012 10:04 am
Location: Uppsala, Sweden
Version: 2017.3.1
OS: Ubuntu 16.04


Return to Canvas

Who is online

Users browsing this forum: No registered users and 1 guest