Android Open Source - 4est Render






From Project

Back to project page 4est.

License

The source code is released under:

MIT License

If you think the Android project 4est listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.wordsaretoys.forest;
/*from  w w w. j a  v a  2 s.c o m*/
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import android.app.Activity;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;

import com.wordsaretoys.rise.utility.Needle;

/**
 * rendering object for gl surface
 * provides timer, gl & worker thread 
 */
public class Render implements GLSurfaceView.Renderer {

  // worker thread
  Worker worker;

  // model objects
  Debris debris;
  Skybox skybox;

  // ui/ai callback functor
  Runnable update;
  
  // frame timing
  long lastTime;
  int frames;
  
  /**
   * ctor
   */
  public Render() {
    worker = new Worker();
    
    update = new Runnable() {
      public void run() {
        Shared.glView.update();
      }
    };
  }
  
  @Override
  public void onSurfaceCreated(GL10 gl, EGLConfig config) {
    GLES20.glClearDepthf(1.0f);
    GLES20.glDepthFunc(GLES20.GL_LEQUAL);
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    GLES20.glClearColor(0.75f, 0.75f, 0.75f, 1);
    GLES20.glDisable(GLES20.GL_BLEND);
    
    // create anything that requires GL context
    skybox = new Skybox();
    // including objects need by others
    Shared.debris = debris = new Debris();
    
    worker.start();
  }

  @Override
  public void onSurfaceChanged(GL10 gl, int width, int height) {
    Shared.player.camera.size(width, height);
  }

  @Override
  public void onDrawFrame(GL10 gl) {

    // update game state and player kinematics
    Shared.rotors.update();
    Shared.player.update();

    // update any android UI elements
    ((Activity) Shared.context).runOnUiThread(update);

    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    GLES20.glEnable(GLES20.GL_CULL_FACE);
    GLES20.glCullFace(GLES20.GL_BACK);
    debris.draw();
    GLES20.glDisable(GLES20.GL_CULL_FACE);
    skybox.draw();
    
    // handle frame counting / timing
      long t = System.nanoTime();
    frames++;
    if (t - lastTime >= 1e9) {
      Shared.dbg.set("fps", frames);
      frames = 0;
      lastTime = t;
    }
  }
  
  /**
   * worker thread for background generation
   */
  class Worker extends Needle {

    public Worker() {
      super("builder", 100);
    }

    @Override
    public void run() {
      resume();
      while (inPump()) {
        debris.update();
      }
    }
    
  }
}




Java Source Code List

com.wordsaretoys.forest.Audio.java
com.wordsaretoys.forest.Debris.java
com.wordsaretoys.forest.Game.java
com.wordsaretoys.forest.GlView.java
com.wordsaretoys.forest.MainActivity.java
com.wordsaretoys.forest.Map.java
com.wordsaretoys.forest.Player.java
com.wordsaretoys.forest.Render.java
com.wordsaretoys.forest.Rotors.java
com.wordsaretoys.forest.Shared.java
com.wordsaretoys.forest.Skybox.java
com.wordsaretoys.rise.geometry.Camera.java
com.wordsaretoys.rise.geometry.Geom.java
com.wordsaretoys.rise.geometry.Mote.java
com.wordsaretoys.rise.geometry.Ortho.java
com.wordsaretoys.rise.geometry.Quaternion.java
com.wordsaretoys.rise.geometry.Vector.java
com.wordsaretoys.rise.glwrapper.Mesh.java
com.wordsaretoys.rise.glwrapper.Shader.java
com.wordsaretoys.rise.glwrapper.Texture.java
com.wordsaretoys.rise.meshutil.HeightMapper.java
com.wordsaretoys.rise.meshutil.IndexBuffer.java
com.wordsaretoys.rise.meshutil.SurfaceMapper.java
com.wordsaretoys.rise.meshutil.VertexBuffer.java
com.wordsaretoys.rise.meshutil.Vindexer.java
com.wordsaretoys.rise.pattern.Bitmap.java
com.wordsaretoys.rise.pattern.F2FSumMap.java
com.wordsaretoys.rise.pattern.I2FCutMap.java
com.wordsaretoys.rise.pattern.I2FMap.java
com.wordsaretoys.rise.pattern.I2IMap.java
com.wordsaretoys.rise.pattern.Pattern.java
com.wordsaretoys.rise.pattern.Ring.java
com.wordsaretoys.rise.utility.Asset.java
com.wordsaretoys.rise.utility.Board.java
com.wordsaretoys.rise.utility.Dbg.java
com.wordsaretoys.rise.utility.Interval.java
com.wordsaretoys.rise.utility.Misc.java
com.wordsaretoys.rise.utility.Needle.java