finally, I got my real 3D render.
the base idea is :
1. create 1 offscreen framebuffer for each eye
2. set the framebuffer to render to a Texture
3. render one eye's view to the texture
4. blit the texture to screen with down scale to 1/2 original size.
then problem comes:
1. after several frames, OOM exception thrown.
many logs like:
I/jPCT-AE ( 574): OpenGL context has changed...trying to recover!
I/jPCT-AE ( 574): OpenGL context has changed...trying to recover!
I/jPCT-AE ( 574): OpenGL context has changed...trying to recover!
I/jPCT-AE ( 574): Additional visibility list (380) created with size: 512
I/jPCT-AE ( 574): OpenGL context has changed...trying to recover!
I/jPCT-AE ( 574): OpenGL context has changed...trying to recover!
I/jPCT-AE ( 574): OpenGL context has changed...trying to recover!
I/jPCT-AE ( 574): Additional visibility list (390) created with size: 512
2. the blit down-scaled image is upside-down.
dear Egon, can you give some advices ? thanks.
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;
import com.threed.jpct.Camera;
import com.threed.jpct.FrameBuffer;
import com.threed.jpct.Logger;
import com.threed.jpct.RGBColor;
import com.threed.jpct.Texture;
import com.tpv.ui.trid.AndroidFrameBlitter;
import com.tpv.ui.trid.TriDScene;
import com.tpv.ui.trid.real3d.Real3DRenderer.Position;
import android.opengl.GLSurfaceView.Renderer;
import android.util.Log;
public class Real3DRenderer implements Renderer {
private TriDScene mScene = null;
private FrameBuffer mFb = null;
private FrameBuffer mBackFb = null;
private Texture mBackTexture = null;
public enum Position {
LEFT,
RIGHT,
};
private Position mPos = Position.LEFT;
private float mSpeed = 0.0f;
private final float SPEED_OFFSET = 0.01f;
public void incAngle() {
// TODO Auto-generated method stub
mSpeed += SPEED_OFFSET;
if(mPos == Position.LEFT)
Log.d("3DUI","left camera speed"+mSpeed);
else
Log.d("3DUI","right camera speed"+mSpeed);
}
public void decAngle() {
// TODO Auto-generated method stub
mSpeed -= SPEED_OFFSET;
if(mSpeed < 0)
mSpeed = 0.0f;
if(mPos == Position.LEFT)
Log.d("3DUI","left camera speed "+mSpeed);
else
Log.d("3DUI","right camera speed "+mSpeed);
}
public Real3DRenderer(TriDScene scene, Position pos){
mScene = scene;
mPos = pos;
}
private RGBColor black = new RGBColor(0, 0, 0, 0);
@Override
public void onDrawFrame(GL10 gl) {
// TODO Auto-generated method stub
mBackFb.clear(black);
if(mPos == Position.LEFT)
mScene.renderFrame(mBackFb, -mSpeed);
else
mScene.renderFrame(mBackFb, mSpeed);
mBackFb.display();
// blit to screen
mFb.clear(black);
mFb.blit(mBackTexture, 0, 0, 0, 0,
mBackTexture.getWidth(), mBackTexture.getHeight(),
mBackTexture.getWidth()/2, mBackTexture.getHeight(),
-1,false, null);
mFb.display();
}
@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
// TODO Auto-generated method stub
if (mFb != null) {
mFb.dispose();
}
mFb = new FrameBuffer(gl, width, height);
Logger.log("==== Launcher launch: " +width+"X" +height+" OpenGL Major Version: "+mFb.getOpenGLMajorVersion());
if(mBackFb != null){
mBackFb.dispose();
}
mBackFb = new FrameBuffer(gl, width*2, height);
mBackTexture = new Texture(width*2, height);
mBackFb.setRenderTarget(mBackTexture);
}
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
// TODO Auto-generated method stub
}
}