121
I see...it shouldn't matter much though, because it's only used for projective texturing, which in most cases, you don't need unless you are using shadow mapping and, well, projective textures.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
package com.threed.jpct.example;
import java.lang.reflect.Field;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import android.app.Activity;
import android.opengl.GLSurfaceView;
import android.os.Bundle;
import android.util.Log;
import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Light;
import com.threed.jpct.Logger;
import com.threed.jpct.Object3D;
import com.threed.jpct.Primitives;
import com.threed.jpct.RGBColor;
import com.threed.jpct.SimpleVector;
import com.threed.jpct.Texture;
import com.threed.jpct.World;
import com.threed.jpct.util.MemoryHelper;
public class HelloWorld extends Activity {
private static HelloWorld master = null;
private GLSurfaceView mGLView;
private MyRenderer renderer = null;
private FrameBuffer fb = null;
private World world = null;
private int fps = 0;
private Light sun = null;
private GL10 lastGl = null;
private RGBColor back = new RGBColor(50, 50, 10);
public Object3D obj;
public Texture texture;
protected void onCreate(Bundle savedInstanceState) {
Logger.log("onCreate");
if (master != null) {
copy(master);
}
super.onCreate(savedInstanceState);
mGLView = new GLSurfaceView(getApplication());
mGLView.setEGLContextClientVersion(2);
mGLView.setPreserveEGLContextOnPause(true);
renderer = new MyRenderer();
mGLView.setRenderer(renderer);
setContentView(mGLView);
}
@Override
protected void onPause() {
super.onPause();
mGLView.onPause();
}
@Override
protected void onResume() {
super.onResume();
mGLView.onResume();
}
@Override
protected void onStop() {
super.onStop();
System.exit(0);
}
private void copy(Object src) {
try {
Logger.log("Copying data from master Activity!");
Field[] fs = src.getClass().getDeclaredFields();
for (Field f : fs) {
f.setAccessible(true);
f.set(this, f.get(src));
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
protected boolean isFullscreenOpaque() {
return true;
}
class MyRenderer implements GLSurfaceView.Renderer {
private long time = System.currentTimeMillis();
public MyRenderer() {
}
public void onSurfaceChanged(GL10 gl, int w, int h) {
// Renew the frame buffer
if (lastGl != gl) {
Log.i("HelloWorld", "Init buffer");
if (fb != null) {
fb.dispose();
}
fb = new FrameBuffer(w, h);
fb.setVirtualDimensions(fb.getWidth(), fb.getHeight());
lastGl = gl;
} else {
fb.resize(w, h);
fb.setVirtualDimensions(w, h);
}
if (master == null) {
world = new World();
world.setAmbientLight(70, 70, 70);
sun = new Light(world);
sun.setIntensity(200, 200, 200);
obj = Primitives.getSphere(50,15);
world.addObject(obj);
obj.translate(0, 0, 0);
obj.build();
// Specular lighting
obj.setSpecularLighting(true);
Camera cam = world.getCamera();
cam.moveCamera(Camera.CAMERA_MOVEOUT, 35);
cam.lookAt(SimpleVector.ORIGIN);
SimpleVector sv = new SimpleVector();
sv.set(SimpleVector.ORIGIN);
sv.y -= 70;
sv.z -= 70;
sun.setPosition(sv);
MemoryHelper.compact();
if (master == null) {
Logger.log("Saving master Activity!");
master = HelloWorld.this;
}
}
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
//
}
public void onDrawFrame(GL10 gl) {
SimpleVector sv=sun.getPosition();
sv.rotateY(0.02f);
sun.setPosition(sv);
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();
if (System.currentTimeMillis() - time >= 1000) {
Logger.log(fps + "fps");
fps = 0;
time = System.currentTimeMillis();
}
fps++;
}
}
public static HelloWorld getApp() {
return master;
}
}