Canvas Element

From FlightGear wiki
Jump to: navigation, search

A handful of rendering primitives are available to draw on a canvas. Properties (see Property Tree for general information on FlightGear's property system) are used to control the appearance and behaviour of such Elements.


Set OpenGL blend function. For a single function for all color channels (as with glBlendFunc) use the properties "blend-source" and "blend-destination". To set separate blend functions for the rgb and alpha channels (as with glBlendFuncSeparate) use the properties with "*-rgb" and "*-alpha" prefix.

  • Format: "dst-alpha" | "dst-color" | "one" | "one-minus-dst-alpha" | "one-minus-dst-color" | "one-minus-src-alpha" | "one-minus-src-color" | "src-alpha" | "src-alpha-saturate" | "src-color" | "constant-color" | "one-minus-constant-color" | "constant-alpha" | "one-minus-constant-alpha" | "zero" (See the OpenGL Reference Pages for details)

Setting different blend functions for rgb and alpha:

# Standard alpha blending
el.set("blend-source-rgb", "src-alpha");
el.set("blend-destination-rgb", "one-minus-src-alpha");

# Just keep current alpha
el.set("blend-source-alpha", "zero");
el.set("blend-destination-alpha", "one");


Cquote1.png Scaling or any other type of transformation or changing the coordinates of individual points is definitely more efficient than clipping (which requires to change the OpenGL clip planes for every rendered object with a different clipping rectangle).
— TheTom (Feb 21st, 2016). Re: Space Shuttle.
(powered by Instant-Cquotes)
element.set("clip" [, format]);

Sets clipping rectangle for element and all its children. Only what is inside the clipping bounds will be shown.

Sets the format for the clipping. Accepted value are "auto" (default) and "rect(top, right, bottom, left)".
Caution format = "rect()" only
The distance of the top side of the clipping boundary from the upper canvas boundary.
Caution format = "rect()" only
The distance of the right side of the clipping boundary from the left canvas boundary.
Caution format = "rect()" only
The distance of the bottom side of the clipping boundary from the upper canvas boundary.
Caution format = "rect()" only
The distance of the left side of the clipping boundary from the left canvas boundary.


# Clip 50 pixels off each side
     .setSize(400, 400)
     .set("clip", "rect(50, 350, 350, 50)");


  • Default: GLOBAL

Set the coordinate reference frame for the clip property.

# set clip reference frame to parent coordinate frame
element.set("clip-frame", canvas.Element.PARENT);




Canvas elements have an optional Z-index, but in the absence of this, the creation order of elements is used. (Creation order becomes the storage order) Most Canvas code I’ve encountered so far is relying on this - child nodes are parsed in XML order, or from SVG which creates elements in SVG order. Usually no Z-indices are specified.[1]

  • Format: <number> (Integer)
  • Default: 0

Change order in which elements are drawn. Elements with higher z-index are drawn later and cover already drawn elements on overlapping parts.

# Draw before all elements (if no z-index of the other elements is lower than zero)
element.set("z-index", -1);

# Ensure element2 is drawn before/below element1
element1.set("z-index", 51);
element2.set("z-index", 50);
  1. James Turner  (Dec 27th, 2016).  [Flightgear-devel] Observation about the Canvas Z-ordering .