Author Topic: Question,how to set two camera in jpct?  (Read 5960 times)

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Question,how to set two camera in jpct?
« on: October 20, 2014, 02:43:01 pm »
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.

« Last Edit: October 22, 2014, 03:49:47 pm by Uncle Ray »

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: Question,how to set two camera in jpct?
« Reply #1 on: October 20, 2014, 05:30:24 pm »
Any tips?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12258
    • View Profile
    • http://www.jpct.net
Re: Question,how to set two camera in jpct?
« Reply #2 on: October 20, 2014, 05:56:29 pm »
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.

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: Question,how to set two camera in jpct?
« Reply #3 on: October 20, 2014, 06:13:13 pm »
thx,a little complicated,but i will tried it,any progresses will reported soon.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12258
    • View Profile
    • http://www.jpct.net
Re: Question,how to set two camera in jpct?
« Reply #4 on: October 20, 2014, 07:09:08 pm »
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.

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: Question,how to set two camera in jpct?
« Reply #5 on: October 21, 2014, 11:11:36 am »
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)?



Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12258
    • View Profile
    • http://www.jpct.net
Re: Question,how to set two camera in jpct?
« Reply #6 on: October 21, 2014, 12:24:09 pm »
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.

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: Question,how to set two camera in jpct?
« Reply #7 on: October 21, 2014, 12:33:01 pm »
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?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12258
    • View Profile
    • http://www.jpct.net
Re: Question,how to set two camera in jpct?
« Reply #8 on: October 21, 2014, 01:35:54 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... ???
« Last Edit: October 21, 2014, 01:44:16 pm by EgonOlsen »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12258
    • View Profile
    • http://www.jpct.net
Re: Question,how to set two camera in jpct?
« Reply #9 on: October 21, 2014, 01:36:31 pm »
I can upload an example later if that would help...

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: Question,how to set two camera in jpct?
« Reply #10 on: October 21, 2014, 02:37:29 pm »
Thx,if there are some examples,that would be much helpful.

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: Question,how to set two camera in jpct?
« Reply #11 on: October 21, 2014, 03:31:45 pm »
got it,but.........



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

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: Question,how to set two camera in jpct?
« Reply #12 on: October 21, 2014, 03:59:05 pm »
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....??? :(
« Last Edit: October 21, 2014, 04:02:15 pm by Uncle Ray »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12258
    • View Profile
    • http://www.jpct.net
Re: Question,how to set two camera in jpct?
« Reply #13 on: October 21, 2014, 04:18:13 pm »
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.

Offline Uncle Ray

  • int
  • **
  • Posts: 81
    • View Profile
Re: Question,how to set two camera in jpct?
« Reply #14 on: October 21, 2014, 05:05:09 pm »


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();   
« Last Edit: October 22, 2014, 04:07:13 pm by Uncle Ray »