Hi fellow wiki editors!

To help newly registered users get more familiar with the wiki (and maybe older users too) there is now a {{Welcome to the wiki}} template. Have a look at it and feel free to add it to new users discussion pages (and perhaps your own).

I have tried to keep the template short, but meaningful. /Johan G

Template talk:Custom Canvas Element

From FlightGear wiki
Jump to: navigation, search

You will want to add a new Canvas::Element whenever you want to add support for features which cannot be currently expressed easily (or efficiently) using existing means (i.e. via existing elements and scripting space frameworks).

For example, this may involve projects requiring camera support, i.e. rendering scenery views to a texture, rendering 3D models to a texture or doing a complete moving map with terrain elevations/height maps (even though the latter could be implemented by sub-classing Canvas::Image to some degree).

Another good example for implementing new elements is rendering file formats like PDF, 3d models or ESRI shape files.

To create a new element, you need to create a new child class which inherits from Canvas::Element base class (or any of its child-classes, e.g. Canvas::Image) and implement the interface of the parent class by providing/overriding the correspond virtual methods.

To add a new element, these are the main steps:

  • Set up a working build environment (including simgear): Building FlightGear
  • Navigate to $SG_SRC/canvas/elements
  • Create a new set of files myElement.cxx myElement.hxx (as per Adding a new Canvas element
  • add them to $SG_SRC/canvas/elements/CMakeLists.txt (as per Developing using CMake)
  • edit $SG_SRC/canvas/elements/CanvasGroups.cxx to add your new element (header and staticInit)
  • begin replacing the stubs with your own C++ code
  • map the corresponding OSG APIs to properties/events understood by Canvas

Below, you can find patches illustrating how to approach each of these steps using boilerplate code, which you will need to customize/replace accordingly:

Note  This element requires a library which is not currently used by SimGear/FlightGear, so that the top-level CMakeLists.txt file needs to be modified to add a corresponding findPackage() call and you need to download/install the corresponding library for building sg/fg. In addition, the module itself may need to be placed in $SG_SRC/CMakeModules: