www.jpct.net
jPCT-AE - a 3d engine for Android => Support => Topic started by: Uncle Ray on October 20, 2014, 02:43:01 pm
-
SOLVED
Thanks for ego's and thomas's great help,the problem solved perfect.
(http://i42.photobucket.com/albums/e308/409544041/cam_zps24380dbc.jpg)
Just two cameras in the same screen,how to implement?
Is the any example?
Thx,ego.
Just a little simple example,any help will be much appreciated.
-
Any tips?
-
The basic approach would be:
- create a texture that should contain the mirror view
- set the camera to one that views the scene from the mirror
- set the mirror texture as render target
- render the scene
- remove the render target
- set the camera back to normal
- render the actual scene
- blit the texture into the mirror
You should use OpenGL ES 2.0 for this or render targets won't work reliable. And it will have a huge impact on your frame rate, because you have to render the scene twice for each frame.
-
thx,a little complicated,but i will tried it,any progresses will reported soon.
-
It's not complicated, it's actually pretty simple. All you do is render the scene twice with different cameras, one time into the mirror texture and one time into the normal frame buffer.
-
I create new world world2,and new Frambuffer fb2.
cam2(world2);
world2.renderScene(fb2);
world2.draw(fb2);
in the second framebuffer,the second camera is ok,but the second framebuffer is location in the(0,0);
how to set the framebuffer's location?
jpct just have framebuffer(width,heght),where is framebuffer_set(x,y)?
-
That's not what i meant. You don't need two FrameBuffers for this. You just a need an additional texture, that you set as a render target of your (single) FrameBuffer instance, render the mirrored scene, remove the render target again and then do the normal rendering.
-
And more,i can't understande which fb.render target(texture tex) used for?
it's just like blit()?
or other use?
in my thought:
1 set camera1 in the world1,and set world1 in the framebuffer1
2 set camera2 in the world2 ,and set world2 in the framebuffer2
3,set framebuffer1 area as Full-screen(ie 1920*1080);
4 set framebuffer2 area as part_screen(ie 256*256);
5,render framebuffer1 and framebuffer2
Is that any wrong with my thought?
-
Is that any wrong with my thought?
Yes: It doesn't work that way, you can't mix frame buffers. A FrameBuffer instance is not much more than a container for some gl context. A render target is exactly what the name says: A target to render into. If you don't set one, the default render target of any FrameBuffer instance is the gl context of your screen. If you set a render target, all rendering happens into that target. With that, you render your mirror scene into a texture and you can then blit that texture later as a mirror view. And you have to switch the camera in one World instance instead of using two worlds unless you want to double all your Object3D instance.
I've actually described the whole process in my first reply. I'm not sure how you came up with an idea that has actually nothing do to with it... ???
-
I can upload an example later if that would help...
-
Thx,if there are some examples,that would be much helpful.
-
got it,but.........
(http://i42.photobucket.com/albums/e308/409544041/test1_zps7c71d273.jpg)
the second camera is reverse....
how to fix it?
-
i really got it(maybe...)
0.texture is no need for some jpg,just" Texture mtexture=new Texture(256,256);"could usefull too.
1.framebuffer contains camera .
2,framebuffer's default render target is all of the scene(ie world)
3.uses setrendertarget could translate framebuffer into texture.
4 blit this texture in the screen.(the texture means second camera)
5,remove target(so the framebuffer back to first camera)
first render:(second camera)
world=>camera2=>framebuffer1=>texture=>framebuffer1.blit(texture)=>framebuffer.display
second render:(first camera)
world=>camera1=>framebuffer1=>framebuffer.display
Question still, why second camera reverse....??? :(
-
That's because that is the default coordinate system that OpenGL uses for the screen. Try to blit with (x,dy,dx,-dy...) instead of (x,0,dx,dy...), i.e. start at the bottom with a negative height.
-
it's Wrong,they just the same camera....
//on start_time
public Texture mtexture=new Texture(256,256);
public framebuffer fb=framebuffer(w,h);
public World world=new World();
//on frame_time
//first rendering
cam.auto(world, cam, Objec3D1);
fb.setRenderTarget(mtexture);
fb.clear();
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();
//second rendering
cam.auto(world, cam, Object3D2);
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.blit(mtexture, 0, 0, 700, 8,256, -256,device_width/2,device_height/4,100,false);
//-256 must be negative,otherwise the second camera would be revise
fb.display();
-
How about the framerate in this case ?
-
a little drop,but not much.
-
How about the framerate in this case ?
maybe you came from china,we can talk in qq
(my qq:409544041)
-
i had made a mistake,they just the same camera....
-
I still failed,i have search all of this forum and google,all of them are not anything about how to set two camera in jpct.
Anyone helps one,thx.
-
i think problem is how to switch camera?
-
You have to use method World.setCameraTo(...) (http://www.jpct.net/jpct-ae/doc/com/threed/jpct/World.html#setCameraTo(com.threed.jpct.Camera))
-
thanks to ego and thomas,the problem solved here is the code.
cam1.cam01=world.getcamera;//
//first rendering
world.setCameraTo(cam2.cam01);
cam2.move(world, missile01,2);
fb.setRenderTarget(mtexture);
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.display();
fb.removeRenderTarget();
//second rendering
world.setCameraTo(cam1.cam01); //without this,two views would be share the same camera.
cam1.move(world,tes1,1);
fb.clear(back);
world.renderScene(fb);
world.draw(fb);
fb.blit(mtexture, 0, 0,device_width*5/6, 8,256, -256,device_width/6,device_height/5,100,false);//-256 must negative,otherwise the second camera would be reverse
fb.display();
}