Skip to content

Commit

Permalink
add the osgearth_simple example
Browse files Browse the repository at this point in the history
  • Loading branch information
gwaldron committed Jan 24, 2024
1 parent 108b9cc commit db8694e
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 11 deletions.
10 changes: 4 additions & 6 deletions docs/source/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,23 @@

#### Error: 'gl_ModelViewMatrix is removed after version 140'

osgEarth works best with OpenSceneGraph that was built with the GL3 or GLCORE profile. If you build OSG with the GL2 profile (which is the default) you may need to take some extra steps.

The most common symptom is error messages like this:
If you build OSG with the GL2 profile (which is the default) you may see errors like this:
```
VERTEX Shader "..." infolog:
0(94) : error C7616: global variable gl_ModelViewMatrix is removed after version 140
0(124) : error C7616: global variable gl_MultiTexCoord1 is removed after version 140
0(125) : error C7616: global variable gl_MultiTexCoord2 is removed after version 140
```

If you see this with an OSG GL2 build, you can include code like this to get things working:
If so, you can include code like this to get things working:
```c++
#include <osgEarth/GLUtils>
#include <osgEarth/ExampleResources>
...
viewer.setRealizeOperation(new GL3RealizeOperation());
MapNodeHelper().configureView(&viewer);
```

The `osgearth_simple.cpp` example shows how to do this in your application.


## Earth File

Expand Down
2 changes: 1 addition & 1 deletion src/applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ IF(NOT OSGEARTH_BUILD_PLATFORM_IPHONE)
SET(TARGET_DEFAULT_APPLICATION_FOLDER "Tools")
ADD_SUBDIRECTORY(osgearth_viewer)
ADD_SUBDIRECTORY(osgearth_imgui)
ADD_SUBDIRECTORY(osgearth_toc)
ADD_SUBDIRECTORY(osgearth_tfs)
ADD_SUBDIRECTORY(osgearth_boundarygen)
ADD_SUBDIRECTORY(osgearth_version)
Expand Down Expand Up @@ -60,6 +59,7 @@ IF(NOT OSGEARTH_BUILD_PLATFORM_IPHONE)
IF(OSGEARTH_BUILD_EXAMPLES)
SET(TARGET_DEFAULT_LABEL_PREFIX "Example")
SET(TARGET_DEFAULT_APPLICATION_FOLDER "Examples")
ADD_SUBDIRECTORY(osgearth_simple)
ADD_SUBDIRECTORY(osgearth_manip)
ADD_SUBDIRECTORY(osgearth_cluster)
ADD_SUBDIRECTORY(osgearth_features)
Expand Down
7 changes: 7 additions & 0 deletions src/applications/osgearth_simple/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
INCLUDE_DIRECTORIES(${OSG_INCLUDE_DIRS} )
SET(TARGET_LIBRARIES_VARS OSG_LIBRARY OSGDB_LIBRARY OSGGA_LIBRARY OSGUTIL_LIBRARY OSGVIEWER_LIBRARY OSGSIM_LIBRARY OSGSHADOW_LIBRARY OSGTEXT_LIBRARY OSGMANIPULATOR_LIBRARY OPENTHREADS_LIBRARY)

SET(TARGET_SRC osgearth_simple.cpp )

#### end var setup ###
SETUP_APPLICATION(osgearth_simple)
76 changes: 76 additions & 0 deletions src/applications/osgearth_simple/osgearth_simple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/* -*-c++-*- */
/* osgEarth - Geospatial SDK for OpenSceneGraph
* Copyright 2020 Pelican Mapping
* http://osgearth.org
*
* osgEarth is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>
*/
#include <osgViewer/Viewer>
#include <osgDB/ReadFile>
#include <osgEarth/MapNode>
#include <osgEarth/EarthManipulator>
#include <osgEarth/GLUtils>
#include <osgEarth/LogarithmicDepthBuffer>
#include <iostream>


int
usage(const char* name, const char* message)
{
std::cerr << "Error: " << message << std::endl;
std::cerr << "Usage: " << name << " file.earth" << std::endl;
return -1;
}


int
main(int argc, char** argv)
{
osg::ArgumentParser arguments(&argc,argv);
if (argc < 2)
return usage(argv[0], "Missing earth file");

// One time osgEarth initialization:
osgEarth::initialize(arguments);

// Load the earth file:
osg::ref_ptr<osg::Node> node = osgDB::readNodeFiles(arguments);
if (!node.valid())
return usage(argv[0], "File not found");

// If the node doesn't contain a MapNode (earth file), bail out:
auto mapNode = osgEarth::MapNode::get(node);
if (!mapNode)
return usage(argv[0], "No MapNode in file");

// Set up a simple viewer with our custom manipulator:
osgViewer::Viewer viewer(arguments);
viewer.setSceneData(node);
viewer.setCameraManipulator(new osgEarth::Util::EarthManipulator(arguments));

// This is optional, but it will mitigate near-plane clipping in a whole earth scene:
osgEarth::Util::LogarithmicDepthBuffer ldb;
ldb.install(viewer.getCamera());

#ifndef OSG_GL3_AVAILABLE
// If your OSG is build with a GL2 profile, install our custom realize op
// to get all the shaders working:
viewer.setRealizeOperation(new osgEarth::GL3RealizeOperation());
#endif

return viewer.run();
}
4 changes: 2 additions & 2 deletions src/osgEarth/LineDrawable.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ void oe_LineDrawable_VS_VIEW(inout vec4 currView)
uniform vec3 oe_Camera;

// Set by GLUtils methods
uniform float oe_GL_LineWidth;
uniform int oe_GL_LineStipplePattern;
uniform float oe_GL_LineWidth = 1.0;
uniform int oe_GL_LineStipplePattern = 0xffff;

// Input attributes for adjacent points
in vec3 oe_LineDrawable_prev;
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarth/PointDrawable.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#pragma vp_location vertex_view
#pragma vp_order last

uniform float oe_GL_PointSize;
uniform float oe_GL_PointSize = 1.0;

void oe_PointDrawable_VS_VIEW(inout vec4 vertexView)
{
Expand Down
2 changes: 1 addition & 1 deletion src/osgEarthDrivers/sky_simple/SimpleSky.Stars.vert.glsl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma vp_entryPoint oe_Stars_VS
#pragma vp_location vertex_clip

uniform float oe_GL_PointSize;
uniform float oe_GL_PointSize = 1.0;
uniform vec3 atmos_v3LightDir;
uniform mat4 osg_ViewMatrixInverse;
out float oe_Stars_visibility;
Expand Down

0 comments on commit db8694e

Please sign in to comment.