Question,how to set two camera in jpct?

Started by Uncle Ray, October 20, 2014, 02:43:01 PM

Previous topic - Next topic

Uncle Ray

SOLVED
Thanks for ego's and thomas's great help,the problem solved perfect.

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.



EgonOlsen

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.

Uncle Ray

thx,a little complicated,but i will tried it,any progresses will reported soon.

EgonOlsen

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.

Uncle Ray

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)?



EgonOlsen

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.

Uncle Ray

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?

EgonOlsen

#8
Quote from: Uncle Ray on October 21, 2014, 12:33:01 PM
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... ???

EgonOlsen

I can upload an example later if that would help...

Uncle Ray

Thx,if there are some examples,that would be much helpful.

Uncle Ray

got it,but.........



the second camera is reverse....
how to fix it?

Uncle Ray

#12
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....??? :(

EgonOlsen

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.

Uncle Ray

#14


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();