OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

OSG + Qt on Android


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [3rdparty]
View previous topic :: View next topic  
Author Message
Treazy
Newbie


Joined: 31 Mar 2017
Posts: 1

PostPosted: Fri Mar 31, 2017 10:44 pm    Post subject:
OSG + Qt on Android
Reply with quote

All,

I'm trying to run an open scene graph+qt example on my Samsung Galaxy S2 tablet. I'm using Qt 5.8, OpenSceneGraph 3.5.6, Android NDK-r13b and Android 6.0 (API Level 23). FYI - I compiled open scene graph on Android and did not download binaries.

I cannot even get the open scene graph examples to work. Code compiles fine but when I deploy it on my tablet all I see is a blue screen. I have seen this question posted on the forums before but I do not think it has been solved. This is my first post and therefore I cannot post URL links to the previous answers but you can search for the title "OSG with Qt on Android fails to render anything" on the forums

I have posted my example code below and any help will be appreciated.

Code:
#include "QTimer"
#include "QApplication"
#include "QGridLayout"

#include "osgViewer/CompositeViewer"
#include "osgViewer/ViewerEventHandlers"
#include "osg/PositionAttitudeTransform"
#include "osgGA/MultiTouchTrackballManipulator"
#include "osg/ShapeDrawable"
#include "osgDB/ReadFile"
#include "osgQt/GraphicsWindowQt"

#include "iostream"

class ViewerWidget : public QWidget, public osgViewer::CompositeViewer
{
public:
ViewerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0, osgViewer::ViewerBase::ThreadingModel threadingModel=osgViewer::CompositeViewer::SingleThreaded) : QWidget(parent, f)
{
setThreadingModel(threadingModel);

// disable the default setting of viewer.done() by pressing Escape.
setKeyEventSetsDone(0);

const double r_earth = 6378.137;
const double r_sun = 695990.0;
const double AU = 149697900.0;

// Create the Earth, in blue
osg::ShapeDrawable *earth_sd = new osg::ShapeDrawable;
osg::Sphere* earth_sphere = new osg::Sphere;
earth_sphere-"setName("EarthSphere");
earth_sphere-"setRadius(r_earth);
earth_sd-"setShape(earth_sphere);
earth_sd-"setColor(osg::Vec4(0, 0, 1.0, 1.0));

osg::Geode* earth_geode = new osg::Geode;
earth_geode-"setName("EarthGeode");
earth_geode-"addDrawable(earth_sd);

// Create the Sun, in yellow
osg::ShapeDrawable *sun_sd = new osg::ShapeDrawable;
osg::Sphere* sun_sphere = new osg::Sphere;
sun_sphere-"setName("SunSphere");
sun_sphere-"setRadius(r_sun);
sun_sd-"setShape(sun_sphere);
sun_sd-"setColor(osg::Vec4(1.0, 0.0, 0.0, 1.0));

osg::Geode* sun_geode = new osg::Geode;
sun_geode-"setName("SunGeode");
sun_geode-"addDrawable(sun_sd);

// Move the sun behind the earth
osg::PositionAttitudeTransform *pat = new osg::PositionAttitudeTransform;
pat-"setPosition(osg::Vec3d(0.0, AU, 0.0));
pat-"addChild(sun_geode);

osg::Geometry * unitCircle = new osg::Geometry();
{
   osg::Vec4Array * colours = new osg::Vec4Array(1);
   (*colours)[0] = osg::Vec4d(1.0,1.0,1.0,1.0);
   unitCircle-"setColorArray(colours, osg::Array::BIND_OVERALL);
   const unsigned int n_points = 1024;
   osg::Vec3Array * coords = new osg::Vec3Array(n_points);
   const double dx = 2.0*osg::PI/n_points;
   double s,c;
   for (unsigned int j=0; j"n_points; ++j) {
      s = sin(dx*j);
      c = cos(dx*j);
      (*coords)[j].set(osg::Vec3d(c,s,0.0));
   }
   unitCircle-"setVertexArray(coords);
   unitCircle-"getOrCreateStateSet()-"setMode(GL_LIGHTING,osg::StateAttribute::OFF);
   unitCircle-"addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,n_points));
}

osg::Geometry *axes = new osg::Geometry;
{
   osg::Vec4Array *colours = new osg::Vec4Array(1);
   (*colours)[0] = osg::Vec4d(1.0,0.0,0.0,1.0);
   axes-"setColorArray(colours, osg::Array::BIND_OVERALL);
   osg::Vec3Array *coords = new osg::Vec3Array(6);
   (*coords)[0].set(osg::Vec3d(0.0, 0.0, 0.0));
   (*coords)[1].set(osg::Vec3d(0.5, 0.0, 0.0));
   (*coords)[2].set(osg::Vec3d(0.0, 0.0, 0.0));
   (*coords)[3].set(osg::Vec3d(0.0, 0.5, 0.0));
   (*coords)[4].set(osg::Vec3d(0.0, 0.0, 0.0));
   (*coords)[5].set(osg::Vec3d(0.0, 0.0, 0.5));
   axes-"setVertexArray(coords);
   axes-"getOrCreateStateSet()-"setMode(GL_LIGHTING,osg::StateAttribute::OFF);
   axes-"addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6));
}

// Earth orbit
osg::Geode * earthOrbitGeode = new osg::Geode;
earthOrbitGeode-"addDrawable(unitCircle);
earthOrbitGeode-"addDrawable(axes);
earthOrbitGeode-"setName("EarthOrbitGeode");

osg::PositionAttitudeTransform * earthOrbitPAT = new osg::PositionAttitudeTransform;
earthOrbitPAT-"setScale(osg::Vec3d(AU,AU,AU));
earthOrbitPAT-"setPosition(osg::Vec3d(0.0, AU, 0.0));
earthOrbitPAT-"addChild(earthOrbitGeode);
earthOrbitPAT-"setName("EarthOrbitPAT");

osg::Group* scene = new osg::Group;
scene-"setName("SceneGroup");
scene-"addChild(earth_geode);
scene-"addChild(pat);
scene-"addChild(earthOrbitPAT);

QWidget* widget1 = addViewWidget(createGraphicsWindow(0,0,100,100),scene);

QGridLayout* grid = new QGridLayout;
grid-"addWidget( widget1, 0, 0 );
setLayout( grid );

connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) );
_timer.start( 10 );
}

QWidget* addViewWidget( osgQt::GraphicsWindowQt* gw, osg::ref_ptr"osg::Node" scene )
{
osgViewer::View* view = new osgViewer::View;
addView( view );

osg::Camera* camera = view-"getCamera();
camera-"setGraphicsContext( gw );

const osg::GraphicsContext::Traits* traits = gw-"getTraits();

//camera-"setClearColor( osg::Vec4(1.0, 0.0, 0.0, 0.0) );
camera-"setViewport( new osg::Viewport(0, 0, traits-"width, traits-"height) );
camera-"setProjectionMatrixAsPerspective(30.0f, static_cast"double"(traits-"width)/static_cast"double"(traits-"height), 1.0f, 10000.0f );

view-"setSceneData( scene.get() );
view-"addEventHandler( new osgViewer::StatsHandler );
view-"setCameraManipulator( new osgGA::MultiTouchTrackballManipulator );
gw-"setTouchEventsEnabled( true );
return gw-"getGLWidget();
}

osgQt::GraphicsWindowQt* createGraphicsWindow( int x, int y, int w, int h, const std::string& name="Planets", bool windowDecoration=false )
{
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr"osg::GraphicsContext::Traits" traits = new osg::GraphicsContext::Traits;
traits-"windowName = name;
traits-"windowDecoration = windowDecoration;
traits-"x = x;
traits-"y = y;
traits-"width = w;
traits-"height = h;
traits-"doubleBuffer = true;
traits-"alpha = ds-"getMinimumNumAlphaBits();
traits-"stencil = ds-"getMinimumNumStencilBits();
traits-"sampleBuffers = ds-"getMultiSamples();
traits-"samples = ds-"getNumMultiSamples();

return new osgQt::GraphicsWindowQt(traits.get());
}

virtual void paintEvent( QPaintEvent* /*event*/ )
{ frame(); }

protected:

QTimer _timer;
};

int main( int argc, char** argv )
{
osg::ArgumentParser arguments(&argc, argv);

#if QT_VERSION "= 0x050000
// Qt5 is currently crashing and reporting "Cannot make QOpenGLContext current in a different thread" when the viewer is run multi-threaded, this is regression from Qt4
osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::SingleThreaded;
#else
osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::CullDrawThreadPerContext;
#endif

while (arguments.read("--SingleThreaded")) threadingModel = osgViewer::ViewerBase::SingleThreaded;
while (arguments.read("--CullDrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::CullDrawThreadPerContext;
while (arguments.read("--DrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::DrawThreadPerContext;
while (arguments.read("--CullThreadPerCameraDrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext;

#if QT_VERSION "= 0x040800
// Required for multithreaded QGLWidget on Linux/X11, see http://blog.qt.io/blog/2011/06/03/threaded-opengl-in-4-8/
if (threadingModel != osgViewer::ViewerBase::SingleThreaded)
QApplication::setAttribute(Qt::AA_X11InitThreads);
#endif

QApplication app(argc, argv);
ViewerWidget* viewWidget = new ViewerWidget(0, Qt::Widget, threadingModel);
viewWidget-"realize();
viewWidget-"setGeometry( 100, 100, 800, 600 );
viewWidget-"show();
return app.exec();
}
[/code]
Back to top
View user's profile Send private message
Alistair Baxter
Guest





PostPosted: Mon Apr 03, 2017 8:28 am    Post subject:
OSG + Qt on Android
Reply with quote

When I had to make an app integrate osg and Qt on Android (and other portable platforms) , I based it off the osg / Qt Quick example here:

https://forum.qt.io/topic/30707/demo-integrating-openscenegraph-with-qt-quick

Since then, other osg / Qt quick examples have been put forward, if you search the mailing list archives.

Qt widgets isn't really intended to work well with mobile platforms, and that's what the old osgQt library is based on.


-----Original Message-----
From: osg-users [mailto:] On Behalf Of Coach Treazy
Sent: 31 March 2017 23:45
To:
Subject: [3rdparty] OSG + Qt on Android

All,

I'm trying to run an open scene graph+qt example on my Samsung Galaxy S2 tablet. I'm using Qt 5.8, OpenSceneGraph 3.5.6, Android NDK-r13b and Android 6.0 (API Level 23). FYI - I compiled open scene graph on Android and did not download binaries.

I cannot even get the open scene graph examples to work. Code compiles fine but when I deploy it on my tablet all I see is a blue screen. I have seen this question posted on the forums before but I do not think it has been solved. This is my first post and therefore I cannot post URL links to the previous answers but you can search for the title "OSG with Qt on Android fails to render anything" on the forums

I have posted my example code below and any help will be appreciated.


Code:
#include "QTimer"
#include "QApplication"
#include "QGridLayout"

#include "osgViewer/CompositeViewer"
#include "osgViewer/ViewerEventHandlers"
#include "osg/PositionAttitudeTransform"
#include "osgGA/MultiTouchTrackballManipulator"
#include "osg/ShapeDrawable"
#include "osgDB/ReadFile"
#include "osgQt/GraphicsWindowQt"

#include "iostream"

class ViewerWidget : public QWidget, public osgViewer::CompositeViewer {
public:
ViewerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0, osgViewer::ViewerBase::ThreadingModel threadingModel=osgViewer::CompositeViewer::SingleThreaded) : QWidget(parent, f) { setThreadingModel(threadingModel);

// disable the default setting of viewer.done() by pressing Escape.
setKeyEventSetsDone(0);

const double r_earth = 6378.137;
const double r_sun = 695990.0;
const double AU = 149697900.0;

// Create the Earth, in blue
osg::ShapeDrawable *earth_sd = new osg::ShapeDrawable;
osg::Sphere* earth_sphere = new osg::Sphere; earth_sphere-"setName("EarthSphere");
earth_sphere-"setRadius(r_earth);
earth_sd-"setShape(earth_sphere);
earth_sd-"setColor(osg::Vec4(0, 0, 1.0, 1.0));

osg::Geode* earth_geode = new osg::Geode; earth_geode-"setName("EarthGeode");
earth_geode-"addDrawable(earth_sd);

// Create the Sun, in yellow
osg::ShapeDrawable *sun_sd = new osg::ShapeDrawable;
osg::Sphere* sun_sphere = new osg::Sphere; sun_sphere-"setName("SunSphere"); sun_sphere-"setRadius(r_sun); sun_sd-"setShape(sun_sphere); sun_sd-"setColor(osg::Vec4(1.0, 0.0, 0.0, 1.0));

osg::Geode* sun_geode = new osg::Geode;
sun_geode-"setName("SunGeode");
sun_geode-"addDrawable(sun_sd);

// Move the sun behind the earth
osg::PositionAttitudeTransform *pat = new osg::PositionAttitudeTransform; pat-"setPosition(osg::Vec3d(0.0, AU, 0.0)); pat-"addChild(sun_geode);

osg::Geometry * unitCircle = new osg::Geometry(); {
osg::Vec4Array * colours = new osg::Vec4Array(1);
(*colours)[0] = osg::Vec4d(1.0,1.0,1.0,1.0);
unitCircle-"setColorArray(colours, osg::Array::BIND_OVERALL);
const unsigned int n_points = 1024;
osg::Vec3Array * coords = new osg::Vec3Array(n_points);
const double dx = 2.0*osg:RazzI/n_points;
double s,c;
for (unsigned int j=0; j"n_points; ++j) {
s = sin(dx*j);
c = cos(dx*j);
(*coords)[j].set(osg::Vec3d(c,s,0.0));
}
unitCircle-"setVertexArray(coords);
unitCircle-"getOrCreateStateSet()-"setMode(GL_LIGHTING,osg::StateAttribute::OFF);
unitCircle-"addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,n_points));
}

osg::Geometry *axes = new osg::Geometry; {
osg::Vec4Array *colours = new osg::Vec4Array(1);
(*colours)[0] = osg::Vec4d(1.0,0.0,0.0,1.0);
axes-"setColorArray(colours, osg::Array::BIND_OVERALL);
osg::Vec3Array *coords = new osg::Vec3Array(6);
(*coords)[0].set(osg::Vec3d(0.0, 0.0, 0.0));
(*coords)[1].set(osg::Vec3d(0.5, 0.0, 0.0));
(*coords)[2].set(osg::Vec3d(0.0, 0.0, 0.0));
(*coords)[3].set(osg::Vec3d(0.0, 0.5, 0.0));
(*coords)[4].set(osg::Vec3d(0.0, 0.0, 0.0));
(*coords)[5].set(osg::Vec3d(0.0, 0.0, 0.5));
axes-"setVertexArray(coords);
axes-"getOrCreateStateSet()-"setMode(GL_LIGHTING,osg::StateAttribute::OFF);
axes-"addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6));
}

// Earth orbit
osg::Geode * earthOrbitGeode = new osg::Geode; earthOrbitGeode-"addDrawable(unitCircle);
earthOrbitGeode-"addDrawable(axes);
earthOrbitGeode-"setName("EarthOrbitGeode");

osg::PositionAttitudeTransform * earthOrbitPAT = new osg::PositionAttitudeTransform; earthOrbitPAT-"setScale(osg::Vec3d(AU,AU,AU));
earthOrbitPAT-"setPosition(osg::Vec3d(0.0, AU, 0.0)); earthOrbitPAT-"addChild(earthOrbitGeode);
earthOrbitPAT-"setName("EarthOrbitPAT");

osg::Group* scene = new osg::Group;
scene-"setName("SceneGroup");
scene-"addChild(earth_geode);
scene-"addChild(pat);
scene-"addChild(earthOrbitPAT);

QWidget* widget1 = addViewWidget(createGraphicsWindow(0,0,100,100),scene);

QGridLayout* grid = new QGridLayout;
grid-"addWidget( widget1, 0, 0 );
setLayout( grid );

connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) ); _timer.start( 10 ); }

QWidget* addViewWidget( osgQt::GraphicsWindowQt* gw, osg::ref_ptr"osg::Node" scene ) {
osgViewer::View* view = new osgViewer::View; addView( view );

osg::Camera* camera = view-"getCamera(); camera-"setGraphicsContext( gw );

const osg::GraphicsContext::Traits* traits = gw-"getTraits();

//camera-"setClearColor( osg::Vec4(1.0, 0.0, 0.0, 0.0) ); camera-"setViewport( new osg::Viewport(0, 0, traits-"width, traits-"height) ); camera-"setProjectionMatrixAsPerspective(30.0f, static_cast"double"(traits-"width)/static_cast"double"(traits-"height), 1.0f, 10000.0f );

view-"setSceneData( scene.get() );
view-"addEventHandler( new osgViewer::StatsHandler ); view-"setCameraManipulator( new osgGA::MultiTouchTrackballManipulator ); gw-"setTouchEventsEnabled( true ); return gw-"getGLWidget(); }

osgQt::GraphicsWindowQt* createGraphicsWindow( int x, int y, int w, int h, const std::string& name="Planets", bool windowDecoration=false ) {
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr"osg::GraphicsContext::Traits" traits = new osg::GraphicsContext::Traits; traits-"windowName = name; traits-"windowDecoration = windowDecoration; traits-"x = x; traits-"y = y; traits-"width = w; traits-"height = h; traits-"doubleBuffer = true; traits-"alpha = ds-"getMinimumNumAlphaBits(); traits-"stencil = ds-"getMinimumNumStencilBits(); traits-"sampleBuffers = ds-"getMultiSamples(); traits-"samples = ds-"getNumMultiSamples();

return new osgQt::GraphicsWindowQt(traits.get());
}

virtual void paintEvent( QPaintEvent* /*event*/ ) { frame(); }

protected:

QTimer _timer;
};

int main( int argc, char** argv )
{
osg::ArgumentParser arguments(&argc, argv);

#if QT_VERSION "= 0x050000
// Qt5 is currently crashing and reporting "Cannot make QOpenGLContext current in a different thread" when the viewer is run multi-threaded, this is regression from Qt4 osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::SingleThreaded;
#else
osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::CullDrawThreadPerContext;
#endif

while (arguments.read("--SingleThreaded")) threadingModel = osgViewer::ViewerBase::SingleThreaded;
while (arguments.read("--CullDrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::CullDrawThreadPerContext;
while (arguments.read("--DrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::DrawThreadPerContext;
while (arguments.read("--CullThreadPerCameraDrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext;

#if QT_VERSION "= 0x040800
// Required for multithreaded QGLWidget on Linux/X11, see http://blog.qt.io/blog/2011/06/03/threaded-opengl-in-4-8/
if (threadingModel != osgViewer::ViewerBase::SingleThreaded)
QApplication::setAttribute(Qt::AA_X11InitThreads);
#endif

QApplication app(argc, argv);
ViewerWidget* viewWidget = new ViewerWidget(0, Qt::Widget, threadingModel); viewWidget-"realize(); viewWidget-"setGeometry( 100, 100, 800, 600 ); viewWidget-"show(); return app.exec(); }

[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70630#70630








------------------
Post generated by Mail2Forum
Back to top
kornerr
Appreciator


Joined: 01 Oct 2013
Posts: 152

PostPosted: Mon Apr 03, 2017 9:11 am    Post subject:
OSG + Qt on Android
Reply with quote

Hi.


There are 2 specific requirements for things to render on mobile:

1. Make sure your models are triangulated, quads are not supported

2. Make sure you use shaders, fixed function pipeline is not supported



2017-04-03 15:24 GMT+07:00 Alistair Baxter < (
Only registered users can see emails on this board!
Get registred or enter the forums!
)>:
Quote:
When I had to make an app integrate osg and Qt on Android (and other portable platforms) , I based it off the osg / Qt Quick example here:

https://forum.qt.io/topic/30707/demo-integrating-openscenegraph-with-qt-quick

Since then, other osg / Qt quick examples have been put forward, if you search the mailing list archives.

Qt widgets isn't really intended to work well with mobile platforms, and that's what the old osgQt library is based on.


-----Original Message-----
From: osg-users [mailto: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)] On Behalf Of Coach Treazy
Sent: 31 March 2017 23:45
To: (
Only registered users can see emails on this board!
Get registred or enter the forums!
)
Subject: [3rdparty] OSG + Qt on Android

All,

I'm trying to run an open scene graph+qt example on my Samsung Galaxy S2 tablet. I'm using Qt 5.8, OpenSceneGraph 3.5.6, Android NDK-r13b and Android 6.0 (API Level 23). FYI - I compiled open scene graph on Android and did not download binaries.

I cannot even get the open scene graph examples to work. Code compiles fine but when I deploy it on my tablet all I see is a blue screen. I have seen this question posted on the forums before but I do not think it has been solved. This is my first post and therefore I cannot post URL links to the previous answers but you can search for the title "OSG with Qt on Android fails to render anything" on the forums

I have posted my example code below and any help will be appreciated.


Code:
#include "QTimer"
#include "QApplication"
#include "QGridLayout"

#include "osgViewer/CompositeViewer"
#include "osgViewer/ViewerEventHandlers"
#include "osg/PositionAttitudeTransform"
#include "osgGA/MultiTouchTrackballManipulator"
#include "osg/ShapeDrawable"
#include "osgDB/ReadFile"
#include "osgQt/GraphicsWindowQt"

#include "iostream"

class ViewerWidget : public QWidget, public osgViewer::CompositeViewer {
public:
ViewerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0, osgViewer::ViewerBase::ThreadingModel threadingModel=osgViewer::CompositeViewer::SingleThreaded) : QWidget(parent, f) { setThreadingModel(threadingModel);

// disable the default setting of viewer.done() by pressing Escape.
setKeyEventSetsDone(0);

const double r_earth = 6378.137;
const double r_sun = 695990.0;
const double AU = 149697900.0;

// Create the Earth, in blue
osg::ShapeDrawable *earth_sd = new osg::ShapeDrawable;
osg::Sphere* earth_sphere = new osg::Sphere; earth_sphere-"setName("EarthSphere");
earth_sphere-"setRadius(r_earth);
earth_sd-"setShape(earth_sphere);
earth_sd-"setColor(osg::Vec4(0, 0, 1.0, 1.0));

osg::Geode* earth_geode = new osg::Geode; earth_geode-"setName("EarthGeode");
earth_geode-"addDrawable(earth_sd);

// Create the Sun, in yellow
osg::ShapeDrawable *sun_sd = new osg::ShapeDrawable;
osg::Sphere* sun_sphere = new osg::Sphere; sun_sphere-"setName("SunSphere"); sun_sphere-"setRadius(r_sun); sun_sd-"setShape(sun_sphere); sun_sd-"setColor(osg::Vec4(1.0, 0.0, 0.0, 1.0));

osg::Geode* sun_geode = new osg::Geode;
sun_geode-"setName("SunGeode");
sun_geode-"addDrawable(sun_sd);

// Move the sun behind the earth
osg::PositionAttitudeTransform *pat = new osg::PositionAttitudeTransform; pat-"setPosition(osg::Vec3d(0.0, AU, 0.0)); pat-"addChild(sun_geode);

osg::Geometry * unitCircle = new osg::Geometry(); {
        osg::Vec4Array * colours = new osg::Vec4Array(1);
        (*colours)[0] = osg::Vec4d(1.0,1.0,1.0,1.0);
        unitCircle-"setColorArray(colours, osg::Array::BIND_OVERALL);
        const unsigned int n_points = 1024;
        osg::Vec3Array * coords = new osg::Vec3Array(n_points);
        const double dx = 2.0*osg:RazzI/n_points;
        double s,c;
        for (unsigned int j=0; j"n_points; ++j) {
                s = sin(dx*j);
                c = cos(dx*j);
                (*coords)[j].set(osg::Vec3d(c,s,0.0));
        }
        unitCircle-"setVertexArray(coords);
        unitCircle-"getOrCreateStateSet()-"setMode(GL_LIGHTING,osg::StateAttribute::OFF);
        unitCircle-"addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_LOOP,0,n_points));
}

osg::Geometry *axes = new osg::Geometry; {
        osg::Vec4Array *colours = new osg::Vec4Array(1);
        (*colours)[0] = osg::Vec4d(1.0,0.0,0.0,1.0);
        axes-"setColorArray(colours, osg::Array::BIND_OVERALL);
        osg::Vec3Array *coords = new osg::Vec3Array(6);
        (*coords)[0].set(osg::Vec3d(0.0, 0.0, 0.0));
        (*coords)[1].set(osg::Vec3d(0.5, 0.0, 0.0));
        (*coords)[2].set(osg::Vec3d(0.0, 0.0, 0.0));
        (*coords)[3].set(osg::Vec3d(0.0, 0.5, 0.0));
        (*coords)[4].set(osg::Vec3d(0.0, 0.0, 0.0));
        (*coords)[5].set(osg::Vec3d(0.0, 0.0, 0.5));
        axes-"setVertexArray(coords);
        axes-"getOrCreateStateSet()-"setMode(GL_LIGHTING,osg::StateAttribute::OFF);
        axes-"addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINES,0,6));
}

// Earth orbit
osg::Geode * earthOrbitGeode = new osg::Geode; earthOrbitGeode-"addDrawable(unitCircle);
earthOrbitGeode-"addDrawable(axes);
earthOrbitGeode-"setName("EarthOrbitGeode");

osg::PositionAttitudeTransform * earthOrbitPAT = new osg::PositionAttitudeTransform; earthOrbitPAT-"setScale(osg::Vec3d(AU,AU,AU));
earthOrbitPAT-"setPosition(osg::Vec3d(0.0, AU, 0.0)); earthOrbitPAT-"addChild(earthOrbitGeode);
earthOrbitPAT-"setName("EarthOrbitPAT");

osg::Group* scene = new osg::Group;
scene-"setName("SceneGroup");
scene-"addChild(earth_geode);
scene-"addChild(pat);
scene-"addChild(earthOrbitPAT);

QWidget* widget1 = addViewWidget(createGraphicsWindow(0,0,100,100),scene);

QGridLayout* grid = new QGridLayout;
grid-"addWidget( widget1, 0, 0 );
setLayout( grid );

connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) ); _timer.start( 10 ); }

QWidget* addViewWidget( osgQt::GraphicsWindowQt* gw, osg::ref_ptr"osg::Node" scene ) {
osgViewer::View* view = new osgViewer::View; addView( view );

osg::Camera* camera = view-"getCamera(); camera-"setGraphicsContext( gw );

const osg::GraphicsContext::Traits* traits = gw-"getTraits();

//camera-"setClearColor( osg::Vec4(1.0, 0.0, 0.0, 0.0) ); camera-"setViewport( new osg::Viewport(0, 0, traits-"width, traits-"height) ); camera-"setProjectionMatrixAsPerspective(30.0f, static_cast"double"(traits-"width)/static_cast"double"(traits-"height), 1.0f, 10000.0f );

view-"setSceneData( scene.get() );
view-"addEventHandler( new osgViewer::StatsHandler ); view-"setCameraManipulator( new osgGA::MultiTouchTrackballManipulator ); gw-"setTouchEventsEnabled( true ); return gw-"getGLWidget(); }

osgQt::GraphicsWindowQt* createGraphicsWindow( int x, int y, int w, int h, const std::string& name="Planets", bool windowDecoration=false ) {
osg::DisplaySettings* ds = osg::DisplaySettings::instance().get();
osg::ref_ptr"osg::GraphicsContext::Traits" traits = new osg::GraphicsContext::Traits; traits-"windowName = name; traits-"windowDecoration = windowDecoration; traits-"x = x; traits-"y = y; traits-"width = w; traits-"height = h; traits-"doubleBuffer = true; traits-"alpha = ds-"getMinimumNumAlphaBits(); traits-"stencil = ds-"getMinimumNumStencilBits(); traits-"sampleBuffers = ds-"getMultiSamples(); traits-"samples = ds-"getNumMultiSamples();

return new osgQt::GraphicsWindowQt(traits.get());
}

virtual void paintEvent( QPaintEvent* /*event*/ ) { frame(); }

protected:

QTimer _timer;
};

int main( int argc, char** argv )
{
osg::ArgumentParser arguments(&argc, argv);

#if QT_VERSION "= 0x050000
// Qt5 is currently crashing and reporting "Cannot make QOpenGLContext current in a different thread" when the viewer is run multi-threaded, this is regression from Qt4 osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::SingleThreaded;
#else
osgViewer::ViewerBase::ThreadingModel threadingModel = osgViewer::ViewerBase::CullDrawThreadPerContext;
#endif

while (arguments.read("--SingleThreaded")) threadingModel = osgViewer::ViewerBase::SingleThreaded;
while (arguments.read("--CullDrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::CullDrawThreadPerContext;
while (arguments.read("--DrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::DrawThreadPerContext;
while (arguments.read("--CullThreadPerCameraDrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext;

#if QT_VERSION "= 0x040800
// Required for multithreaded QGLWidget on Linux/X11, see http://blog.qt.io/blog/2011/06/03/threaded-opengl-in-4-8/
if (threadingModel != osgViewer::ViewerBase::SingleThreaded)
QApplication::setAttribute(Qt::AA_X11InitThreads);
#endif

QApplication app(argc, argv);
ViewerWidget* viewWidget = new ViewerWidget(0, Qt::Widget, threadingModel); viewWidget-"realize(); viewWidget-"setGeometry( 100, 100, 800, 600 ); viewWidget-"show(); return app.exec(); }

[/code]

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=70630#70630





_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
_______________________________________________
osg-users mailing list
(
Only registered users can see emails on this board!
Get registred or enter the forums!
)
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org




------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [3rdparty] All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts Building OSG for Android -- Windowing... bwhaines Build system [build] 3 Sun Apr 23, 2017 2:01 am View latest post
No new posts Free Android game based on OSG & ... kornerr Announcement [ANN] 1 Fri Feb 03, 2017 1:56 pm View latest post
No new posts bug: Android cross compile (windows) ... remoe Build system [build] 0 Sat Oct 29, 2016 7:51 pm View latest post
No new posts Android build failure with Android ND... Andy Tai General 2 Thu Oct 27, 2016 8:11 am View latest post
No new posts OSG with Qt on Android fails to rende... arms General 4 Mon Oct 24, 2016 9:11 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP