Using the API¶
How do I place a 3D model on the map?¶
osgEarth::GeoTransform class inherits from
osg::Transform and will convert map coordinates into OSG world coordinates for you. Place an object at a geospatial position like this:
GeoTransform* xform = new GeoTransform(); GeoPoint point(srs, -121.0, 34.0, 1000.0); xform->setPosition(point);
If you want your object to automatically clamp to the terrain surface, assign a terrain and leave off the altitude:
GeoTransform* xform = new GeoTransform(); xform->setTerrain(mapNode->getTerrain()); GeoPoint point(srs, -121.0, 34.0); xform->setPosition(point);
Why does my model have no texture or lighting?¶
Everything under an osgEarth scene graph is rendered with shaders. So, when using your own models (or creating geometry by hand) you need to create shader components in order for them to render properly.
osgEarth has a built-in shader generator for this purpose. Run the shader generator on your node like so:
osgEarth::Registry::shaderGenerator().run( myNode );
After that, your node will contain shader snippets that allows osgEarth to render it properly and for it to work with other osgEarth features like sky lighting.
Why are my Lines or Annotations not rendering?¶
Lines render using a shader that requires some initial state to be set. You can apply this state to your top-level camera (or anywhere else above the geometry) like so:
#include <osgEarth/GLUtils> ... GLUtils::setGlobalDefaults(camera->getOrCreateStateSet());
For Annotations (
PlaceNodes, etc.) best practice is to place an Annotation node as a descendant of the
MapNode in your scene graph. You can also add them to an
AnnotationLayer and add that layer to the Map.
Annotations need access to the
MapNode in order to render properly. If you cannot place them under the
MapNode, you will have to manually install a few things to make them work:
#include <osgEarth/CullingUtils> #include <osgEarth/GLUtils> ... // Manully assign the MapNode to your annotation annotationNode->setMapNode(mapNode); // In some group above the annotation, install this callback group->addCullCallback(new InstallViewportSizeUniform()); // In some group above the annotation, set the GL defaults GLUtils::setGlobalDefaults(group->getOrCreateStateSet());
Again: MapNode does all this automatically so this is only necessary if you do not place your annotations as descendants of the MapNode.
Text annotations (LabelNode, PlaceNode) are not rendering. Why?¶
Rendering text requires that you disable OSG’s small-feature culling like so:
Note: you must do this for each camera.
Community and Support¶
What is the best practice for using GitHub?¶
The best way to work with the osgEarth repository is to make your own clone on GitHub and to work from that clone. Why not work directly against the main repository? You can, but if you need to make changes, bug fixes, etc., you will need your own clone in order to issue Pull Requests.
- Create your own GitHub account and log in.
- Clone the osgEarth repo.
- Work from your clone. Sync it to the main repository periodically to get the latest changes.
How do I submit changes to osgEarth?¶
We accept contributions and bug fixes through GitHub’s Pull Request mechanism.
First you need your own GitHub account and a fork of the repo (see above). Next, follow these guidelines:
- Create a branch in which to make your changes.
- Make the change.
- Issue a pull request against the main osgEarth repository.
- We will review the PR for inclusion.
If we decide NOT to include your submission, you can still keep it in our cloned repository and use it yourself. Doing so maintains compliance with the osgEarth license since your changes are still available to the public - even if they are not merged into the master repository.