I also have been trying to run this rajawali tutorial using next code.
Class RajawaliTutorialActivity
package rajawali.tutorials;
import rajawali.RajawaliActivity;
import android.os.Bundle;
public class RajawaliTutorialActivity extends RajawaliActivity {
public RajawaliTutorialRenderer mRenderer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mRenderer = new RajawaliTutorialRenderer(this);
mRenderer.setSurfaceView(mSurfaceView);
super.setRenderer(mRenderer);
}
}
Class RajawaliTutorialRenderer
package rajawali.tutorials;
import javax.microedition.khronos.opengles.GL10;
import android.content.Context;
import rajawali.Camera;
import rajawali.Object3D;
import rajawali.lights.DirectionalLight;
import rajawali.materials.Material;
import rajawali.materials.textures.ATexture.TextureException;
import rajawali.materials.textures.Texture;
import rajawali.primitives.Sphere;
import rajawali.renderer.RajawaliRenderer;
public class RajawaliTutorialRenderer extends RajawaliRenderer {
public DirectionalLight light;
public Object3D sphere;
public Context context;
public Camera camera;
public RajawaliTutorialRenderer(Context context) {
super(context);
this.context = context;
setFrameRate(60);
}
public void initScene() {
light = new DirectionalLight(1f, 0.2f, -1.0f); // set the direction
light.setColor(1.0f, 1.0f, 1.0f);
light.setPower(2);
try{
Material material = new Material();
material.addTexture(new Texture("earthColors", R.drawable.earthtruecolor_nasa_big));
material.setColorInfluence(0);
sphere = new Sphere(1, 24, 24);
sphere.setMaterial(material);
getCurrentScene().addLight(light);
super.addChild(sphere);
} catch (TextureException e){
e.printStackTrace();
}
getCurrentCamera().setZ(4.2f);
}
@Override
public void onDrawFrame(GL10 glUnused) {
super.onDrawFrame(glUnused);
sphere.setRotY(sphere.getRotY() + 1);
}
}
See that changes are:
- declare
sphere
object asObject3D
insteadSphere
. - change
DiffuseMaterial
byMaterial
for material declaration. - change parameters to get
Texture
. First parameter is an custom identifier and second parameter is the resource id. - add the line
material.setColorInfluence(0);
after load texture, if this line isn't added, the "heart" becomes red (I'm not sure why). - replace
sphere
object by scene object (accessing withgetCurrentScene
method) to calladdLight
method. - Add try/catch for line
material.addTexture()
as this method now throws a TextureException - add
getCurrentCamera().setZ(4.2f);
to the end of initScene