<div dir="ltr"><div>Hi.<br></div><div><br>There are 2 specific requirements for things to render on mobile:<br></div><div>1. Make sure your models are triangulated, quads are not supported<br></div><div>2. Make sure you use shaders, fixed function pipeline is not supported<br></div></div><div class="gmail_extra"><br><div class="gmail_quote">2017-04-03 15:24 GMT+07:00 Alistair Baxter <span dir="ltr"><<a href="mailto:alistair@mve.com" target="_blank">alistair@mve.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">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:<br>
<br>
<a href="https://forum.qt.io/topic/30707/demo-integrating-openscenegraph-with-qt-quick" rel="noreferrer" target="_blank">https://forum.qt.io/topic/<wbr>30707/demo-integrating-<wbr>openscenegraph-with-qt-quick</a><br>
<br>
Since then, other osg / Qt quick examples have been put forward, if you search the mailing list archives.<br>
<br>
Qt widgets isn't really intended to work well with mobile platforms, and that's what the old osgQt library is based on.<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
-----Original Message-----<br>
From: osg-users [mailto:<a href="mailto:osg-users-bounces@lists.openscenegraph.org">osg-users-bounces@<wbr>lists.openscenegraph.org</a>] On Behalf Of Coach Treazy<br>
Sent: 31 March 2017 23:45<br>
To: <a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
Subject: [osg-users] [3rdparty] OSG + Qt on Android<br>
<br>
All,<br>
<br>
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.<br>
<br>
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<br>
<br>
I have posted my example code below and any help will be appreciated.<br>
<br>
<br>
Code:<br>
#include "QTimer"<br>
#include "QApplication"<br>
#include "QGridLayout"<br>
<br>
#include "osgViewer/CompositeViewer"<br>
#include "osgViewer/<wbr>ViewerEventHandlers"<br>
#include "osg/<wbr>PositionAttitudeTransform"<br>
#include "osgGA/<wbr>MultiTouchTrackballManipulator<wbr>"<br>
#include "osg/ShapeDrawable"<br>
#include "osgDB/ReadFile"<br>
#include "osgQt/GraphicsWindowQt"<br>
<br>
#include "iostream"<br>
<br>
class ViewerWidget : public QWidget, public osgViewer::CompositeViewer {<br>
public:<br>
ViewerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0, osgViewer::ViewerBase::<wbr>ThreadingModel threadingModel=osgViewer::<wbr>CompositeViewer::<wbr>SingleThreaded) : QWidget(parent, f) { setThreadingModel(<wbr>threadingModel);<br>
<br>
// disable the default setting of viewer.done() by pressing Escape.<br>
setKeyEventSetsDone(0);<br>
<br>
const double r_earth = 6378.137;<br>
const double r_sun = 695990.0;<br>
const double AU = 149697900.0;<br>
<br>
// Create the Earth, in blue<br>
osg::ShapeDrawable *earth_sd = new osg::ShapeDrawable;<br>
osg::Sphere* earth_sphere = new osg::Sphere; earth_sphere-"setName("<wbr>EarthSphere");<br>
earth_sphere-"setRadius(r_<wbr>earth);<br>
earth_sd-"setShape(earth_<wbr>sphere);<br>
earth_sd-"setColor(osg::Vec4(<wbr>0, 0, 1.0, 1.0));<br>
<br>
osg::Geode* earth_geode = new osg::Geode; earth_geode-"setName("<wbr>EarthGeode");<br>
earth_geode-"addDrawable(<wbr>earth_sd);<br>
<br>
// Create the Sun, in yellow<br>
osg::ShapeDrawable *sun_sd = new osg::ShapeDrawable;<br>
osg::Sphere* sun_sphere = new osg::Sphere; sun_sphere-"setName("<wbr>SunSphere"); sun_sphere-"setRadius(r_sun); sun_sd-"setShape(sun_sphere); sun_sd-"setColor(osg::Vec4(1.<wbr>0, 0.0, 0.0, 1.0));<br>
<br>
osg::Geode* sun_geode = new osg::Geode;<br>
sun_geode-"setName("SunGeode")<wbr>;<br>
sun_geode-"addDrawable(sun_sd)<wbr>;<br>
<br>
// Move the sun behind the earth<br>
osg::PositionAttitudeTransform *pat = new osg::<wbr>PositionAttitudeTransform; pat-"setPosition(osg::Vec3d(0.<wbr>0, AU, 0.0)); pat-"addChild(sun_geode);<br>
<br>
osg::Geometry * unitCircle = new osg::Geometry(); {<br>
osg::Vec4Array * colours = new osg::Vec4Array(1);<br>
(*colours)[0] = osg::Vec4d(1.0,1.0,1.0,1.0);<br>
unitCircle-"setColorArray(<wbr>colours, osg::Array::BIND_OVERALL);<br>
const unsigned int n_points = 1024;<br>
osg::Vec3Array * coords = new osg::Vec3Array(n_points);<br>
const double dx = 2.0*osg::PI/n_points;<br>
double s,c;<br>
for (unsigned int j=0; j"n_points; ++j) {<br>
s = sin(dx*j);<br>
c = cos(dx*j);<br>
(*coords)[j].set(osg::Vec3d(c,<wbr>s,0.0));<br>
}<br>
unitCircle-"setVertexArray(<wbr>coords);<br>
unitCircle-"<wbr>getOrCreateStateSet()-"<wbr>setMode(GL_LIGHTING,osg::<wbr>StateAttribute::OFF);<br>
unitCircle-"addPrimitiveSet(<wbr>new osg::DrawArrays(osg::<wbr>PrimitiveSet::LINE_LOOP,0,n_<wbr>points));<br>
}<br>
<br>
osg::Geometry *axes = new osg::Geometry; {<br>
osg::Vec4Array *colours = new osg::Vec4Array(1);<br>
(*colours)[0] = osg::Vec4d(1.0,0.0,0.0,1.0);<br>
axes-"setColorArray(colours, osg::Array::BIND_OVERALL);<br>
osg::Vec3Array *coords = new osg::Vec3Array(6);<br>
(*coords)[0].set(osg::Vec3d(0.<wbr>0, 0.0, 0.0));<br>
(*coords)[1].set(osg::Vec3d(0.<wbr>5, 0.0, 0.0));<br>
(*coords)[2].set(osg::Vec3d(0.<wbr>0, 0.0, 0.0));<br>
(*coords)[3].set(osg::Vec3d(0.<wbr>0, 0.5, 0.0));<br>
(*coords)[4].set(osg::Vec3d(0.<wbr>0, 0.0, 0.0));<br>
(*coords)[5].set(osg::Vec3d(0.<wbr>0, 0.0, 0.5));<br>
axes-"setVertexArray(coords);<br>
axes-"getOrCreateStateSet()-"<wbr>setMode(GL_LIGHTING,osg::<wbr>StateAttribute::OFF);<br>
axes-"addPrimitiveSet(new osg::DrawArrays(osg::<wbr>PrimitiveSet::LINES,0,6));<br>
}<br>
<br>
// Earth orbit<br>
osg::Geode * earthOrbitGeode = new osg::Geode; earthOrbitGeode-"addDrawable(<wbr>unitCircle);<br>
earthOrbitGeode-"addDrawable(<wbr>axes);<br>
earthOrbitGeode-"setName("<wbr>EarthOrbitGeode");<br>
<br>
osg::PositionAttitudeTransform * earthOrbitPAT = new osg::<wbr>PositionAttitudeTransform; earthOrbitPAT-"setScale(osg::<wbr>Vec3d(AU,AU,AU));<br>
earthOrbitPAT-"setPosition(<wbr>osg::Vec3d(0.0, AU, 0.0)); earthOrbitPAT-"addChild(<wbr>earthOrbitGeode);<br>
earthOrbitPAT-"setName("<wbr>EarthOrbitPAT");<br>
<br>
osg::Group* scene = new osg::Group;<br>
scene-"setName("SceneGroup");<br>
scene-"addChild(earth_geode);<br>
scene-"addChild(pat);<br>
scene-"addChild(earthOrbitPAT)<wbr>;<br>
<br>
QWidget* widget1 = addViewWidget(<wbr>createGraphicsWindow(0,0,100,<wbr>100),scene);<br>
<br>
QGridLayout* grid = new QGridLayout;<br>
grid-"addWidget( widget1, 0, 0 );<br>
setLayout( grid );<br>
<br>
connect( &_timer, SIGNAL(timeout()), this, SLOT(update()) ); _timer.start( 10 ); }<br>
<br>
QWidget* addViewWidget( osgQt::GraphicsWindowQt* gw, osg::ref_ptr"osg::Node" scene ) {<br>
osgViewer::View* view = new osgViewer::View; addView( view );<br>
<br>
osg::Camera* camera = view-"getCamera(); camera-"setGraphicsContext( gw );<br>
<br>
const osg::GraphicsContext::Traits* traits = gw-"getTraits();<br>
<br>
//camera-"setClearColor( osg::Vec4(1.0, 0.0, 0.0, 0.0) ); camera-"setViewport( new osg::Viewport(0, 0, traits-"width, traits-"height) ); camera-"<wbr>setProjectionMatrixAsPerspecti<wbr>ve(30.0f, static_cast"double"(traits-"<wbr>width)/static_cast"double"(<wbr>traits-"height), 1.0f, 10000.0f );<br>
<br>
view-"setSceneData( scene.get() );<br>
view-"addEventHandler( new osgViewer::StatsHandler ); view-"setCameraManipulator( new osgGA::<wbr>MultiTouchTrackballManipulator ); gw-"setTouchEventsEnabled( true ); return gw-"getGLWidget(); }<br>
<br>
osgQt::GraphicsWindowQt* createGraphicsWindow( int x, int y, int w, int h, const std::string& name="Planets", bool windowDecoration=false ) {<br>
osg::DisplaySettings* ds = osg::DisplaySettings::<wbr>instance().get();<br>
osg::ref_ptr"osg::<wbr>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()<wbr>; traits-"sampleBuffers = ds-"getMultiSamples(); traits-"samples = ds-"getNumMultiSamples();<br>
<br>
return new osgQt::GraphicsWindowQt(<wbr>traits.get());<br>
}<br>
<br>
virtual void paintEvent( QPaintEvent* /*event*/ ) { frame(); }<br>
<br>
protected:<br>
<br>
QTimer _timer;<br>
};<br>
<br>
int main( int argc, char** argv )<br>
{<br>
osg::ArgumentParser arguments(&argc, argv);<br>
<br>
#if QT_VERSION "= 0x050000<br>
// 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::<wbr>ThreadingModel threadingModel = osgViewer::ViewerBase::<wbr>SingleThreaded;<br>
#else<br>
osgViewer::ViewerBase::<wbr>ThreadingModel threadingModel = osgViewer::ViewerBase::<wbr>CullDrawThreadPerContext;<br>
#endif<br>
<br>
while (arguments.read("--<wbr>SingleThreaded")) threadingModel = osgViewer::ViewerBase::<wbr>SingleThreaded;<br>
while (arguments.read("--<wbr>CullDrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::<wbr>CullDrawThreadPerContext;<br>
while (arguments.read("--<wbr>DrawThreadPerContext")) threadingModel = osgViewer::ViewerBase::<wbr>DrawThreadPerContext;<br>
while (arguments.read("--<wbr>CullThreadPerCameraDrawThreadP<wbr>erContext")) threadingModel = osgViewer::ViewerBase::<wbr>CullThreadPerCameraDrawThreadP<wbr>erContext;<br>
<br>
#if QT_VERSION "= 0x040800<br>
// Required for multithreaded QGLWidget on Linux/X11, see <a href="http://blog.qt.io/blog/2011/06/03/threaded-opengl-in-4-8/" rel="noreferrer" target="_blank">http://blog.qt.io/blog/2011/<wbr>06/03/threaded-opengl-in-4-8/</a><br>
if (threadingModel != osgViewer::ViewerBase::<wbr>SingleThreaded)<br>
QApplication::setAttribute(Qt:<wbr>:AA_X11InitThreads);<br>
#endif<br>
<br>
QApplication app(argc, argv);<br>
ViewerWidget* viewWidget = new ViewerWidget(0, Qt::Widget, threadingModel); viewWidget-"realize(); viewWidget-"setGeometry( 100, 100, 800, 600 ); viewWidget-"show(); return app.exec(); }<br>
<br>
[/code]<br>
<br>
------------------<br>
Read this topic online here:<br>
<a href="http://forum.openscenegraph.org/viewtopic.php?p=70630#70630" rel="noreferrer" target="_blank">http://forum.openscenegraph.<wbr>org/viewtopic.php?p=70630#<wbr>70630</a><br>
<br>
<br>
<br>
<br>
<br>
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.<wbr>org/listinfo.cgi/osg-users-<wbr>openscenegraph.org</a><br>
______________________________<wbr>_________________<br>
osg-users mailing list<br>
<a href="mailto:osg-users@lists.openscenegraph.org">osg-users@lists.<wbr>openscenegraph.org</a><br>
<a href="http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org" rel="noreferrer" target="_blank">http://lists.openscenegraph.<wbr>org/listinfo.cgi/osg-users-<wbr>openscenegraph.org</a><br>
</div></div></blockquote></div><br></div>