[osg-users] Can I use Material, Color, LightSource, etc. in Android?

Daniel Ponsoda dponsoda at gmail.com
Thu Jul 19 03:02:17 PDT 2018


I'm playing with the OSG sample code for Android (GLES2) and as I see, it attaches user defined GLSL shaders to the drawable objects in order to display them with the proper shading effects.

Is it not possible to use the OSG API Objects such as Material, Color, LightSource etc. when programming for Android?

I tried them but all I get is plain color shapes for my 3d objects with no shading effects at all as we can see in the PC version of the sample code.

I tried this code (scene draws shaded on Windows, but with plain colors on Android):


// Create a light source
osg::LightSource ls = new LightSource;
ls->getLight()->setPosition(Vec4(10, 10, 20, 0)); 
ls->getLight()->setAmbient(Vec4(0.2, 0.2, 0.2, 1.0));
ls->getLight()->setDiffuse(Vec4(0.7, 0.4, 0.6, 1.0));
ls->getLight()->setSpecular(Vec4(1.0, 1.0, 1.0, 1.0));

// Create a sphere
ShapeDrawable* sphere = new ShapeDrawable(new Sphere(Vec3f(0, 0, 0), 2));
Material *material = new Material();
material->setDiffuse(Material::FRONT, Vec4(0, 1, 0, 1));

Is there a portable way to do this in Android?

Thank you!


Read this topic online here:

More information about the osg-users mailing list