Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I also have been trying to run this rajawali tutorial using next code.<br><br></p> <p>Class <b>RajawaliTutorialActivity</b></p> <pre><code>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); } } </code></pre> <p><br><br> Class <b>RajawaliTutorialRenderer</b></p> <pre><code>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); } } </code></pre> <p>See that changes are:</p> <ol> <li>declare <code>sphere</code> object as <code>Object3D</code> instead <code>Sphere</code>.</li> <li>change <code>DiffuseMaterial</code> by <code>Material</code> for material declaration.</li> <li>change parameters to get <code>Texture</code>. First parameter is an custom identifier and second parameter is the resource id.</li> <li>add the line <code>material.setColorInfluence(0);</code> after load texture, if this line isn't added, the "heart" becomes red (I'm not sure why).</li> <li>replace <code>sphere</code> object by scene object (accessing with <code>getCurrentScene</code> method) to call <code>addLight</code> method.</li> <li>Add try/catch for line <code>material.addTexture()</code> as this method now throws a TextureException</li> <li>add <code>getCurrentCamera().setZ(4.2f);</code> to the end of initScene</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload