Showing posts with label openscenegraph. Show all posts
Showing posts with label openscenegraph. Show all posts

Tuesday, December 4, 2012

Building OpenSceneGraph with Android NDK

I have been rapidly picking up Android development for the last 2 days with Native coding in C++ thrown in. Cross compiling for embedded systems is nothing new for me having played with Beagleboards in various incarnations, the Hawkboard and Pandaboard. Neither is JNI, I did a fair bit of JNI work while at CSIRO trying to make NetCDF faster.

So to build OpenSceneGraph for Android (I am using my Nexus S running 4.2), do the obvious:
  • Get OSG source
  • Get ADK
  • Get NDK
  • Get ADT if you are Eclipse fan like me
  • Get Sequoyah, CDT and whatever else Eclipse wants to build native code.
Build OSG for Android with whatever hack you can imagine. I ended up getting CMake to generate with NMake build files, but built directly using ndk_build afterwards since the MSYS shell could not access DOS commands ndk-build seems to call. Install automation did not work either so I copied OSG headers over by hand into the build directory. It took a while to build, the NDK compilers are rather slow, in the future I will run with -j 12 to take advantage of all my cores.

The next bit was rather easy since the OSG Android sample is already configured for Eclipse. I had to fix up settings with MSYS for bash. Most tutorials refer to cygwin for Linuxy utilities, but I loathe cygwin and I already a have a bunch of MSYS installs floating around through OSGeo4W and Git-bash. The include files and compiler checks are rather strict in Eclipse and any errors in the IDE will prevent uploading the build, be naughty and just delete the errors due to ADT bugs. This is just a proof of concept after all. I had to change a few little things like false to JNI_FALSE to keep the compiler happy. After some toing and froing with gnustl_static, the whole thing built and ran fine.



I wanted to have jpeg textures embedded in the .ive and .osgb files displayed as well as load models with PagedLOD's over http. So I needed to link the little trivial application to curl and jpeg in their Android native incarnations. The hard work has been done already and you can get thirdparty bundles. The first attempt with 8192x8192 textures expectly blew up on the little platform, but atleast libjpeg seemed to be working, I squished textures down to something sane. Libcurl works to download a file hosted on our webserver just fine, but you can't wait for an eternity on this plaform, unless the basefile is a few kb and links to the rest via LOD's the GL context will be lost before the download finishes. Overall it was a fun experiment and I am glad i managed to load a Jesus statue to celebrate this festive season - though it represents death rather than birth.

Tuesday, October 30, 2012

Trivial CMAKE for OpenSceneGraph

It is often fun to get open source projects working with Visual Studio since a lot of build systems leave out a few Microsoft specific vagaries. With CMAKE life in the last few years has become much easier, though sometimes it requires a bit of digging to locate the right incantations to pull in the right dependencies for a trivial project.

CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
PROJECT(AeroViewer)

SET(TARGET_SRC aeroviewer.cpp )

find_package(OpenSceneGraph REQUIRED osgDB osgUtil osgGA osgViewer osgText)

ADD_EXECUTABLE(aeroviewer ${TARGET_SRC})

INCLUDE_DIRECTORIES(${OPENSCENEGRAPH_INCLUDE_DIRS})
TARGET_LINK_LIBRARIES(aeroviewer ${OPENSCENEGRAPH_LIBRARIES})  


The aim of this quick dash is to add a screen overlay with the company logo to the default osgViewer. This requires adding a geometry node to the scene with some static geometry in camera space. Which ends up being equivalent to a HUD in osg parlance. After a bit of tweaking and rotations in texture space I got this, not too bad for a cold-start in OSG land. This bit of sample code is better for HUD's than the tutorial, the required projection and modelview matrices are encapsulated by the CameraNode.