jPCT-AE - a 3d engine for Android > Support

jPCT and real 3D

<< < (2/4) > >>

guillaume:

--- Quote from: EgonOlsen on September 21, 2012, 05:05:12 pm ---You can render the scene multiple times with different cameras...if that does any good.

--- End quote ---
actually, after setup the world, I want to clone the world's camera
to two new cameras,  but there is no clone method for camera ,
how should I do it ?thanks

EgonOlsen:
Like so:


--- Code: ---Camera cam2=new Camera();
cam2.setFOV(cam.getFOV());
cam2.setPosition(cam.getPosition());
cam2.setBack(cam.getBack().cloneMatrix());

--- End code ---

guillaume:
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.


--- Code: ---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

}

}

--- End code ---

EgonOlsen:
You are not supposed to use multiple FrameBuffer instances at a time. This makes jPCT-AE think that the context has changed each time you render into it, which is why it behaves the way it does. You should be able to rewrite the code to use one buffer instead. If you assign a render target, the actual buffer size will be overriden by the size of the texture.

EgonOlsen:
About things being upside down: That's caused by the way gls coordinate system works. You can try to blit with a negative height...you should be able to find something about this somewhere around here.

Edit: Like so:


fb.blit(renderTarget, 0, 0, 0, fb.getHeight(), fb.getWidth(), fb.getHeight(), fb.getWidth(), -fb.getHeight(), -1, false, null);

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version