screenshoot of second camera, texture to object

Blitz3D Forums/Blitz3D Beginners Area/screenshoot of second camera, texture to object

Santiworld(Posted 2009) [#1]
hi... i have a 3d scene in blitz...
in this scene, i have a 3d object, a monitor, and i want to see in the 3d monitor the image from another camera.. can i do that?

in camera1, i have my scene
in camera2, i'm going to have another part of the scene, that i want to see from 3d monitor in the scene of camera1

this is like if i wanted to make a mirror on a car, or the monitor inside the copick of aircraft...

and i need to capture the image each frame.

thanks for your help.. :)


Ross C(Posted 2009) [#2]
Copyrect on the frontbuffer after a render and flip, to a texture. You can apply this texture to an entity and it will act as a mirror. Or, if the mirror is going to be flat and completely facing the camera, simply change the camera's viewport, so it fits into where you want the mirror.


_PJ_(Posted 2009) [#3]
I am not sure, but would it be quicker just displaying the viewport with a second render before the flip?

It seems extraneous to copy to a texture too.

Or is it faster to render to a separate buffer that's not rendered to the backbuffer?


SLotman(Posted 2009) [#4]
It depends... if the "monitor" is just a flat square on the screen, he can get away just making a new viewport, but if it moves, if it's tilted somehow or can be viewed from more than one static pov, then there's no way other than rendering it to a texture and using that texture on a 3d model.

Too bad B3D doesn't have a direct render to texture, and we have to use this Copyrect trick...


Ross C(Posted 2009) [#5]
If you can spare the cash for the fast extend, that comes with a speedy render to texture. If you do decide to copyrect to a texture, make sure you use the VRAM flag.


Santiworld(Posted 2009) [#6]
thanks..

so, i have my 3d monitor in perspective, i have only one option, copyrect.

copyrect is no to fast?... maibe i should use a optimization, something like not copyrect each frame... or somethig like that.

i want to do something like this (the image) in simulators like this when you can turn the view direction.
how'd they do this? (see the monitors imagen)
i suppouse copyrect is my option.




thanks..


Ross C(Posted 2009) [#7]
I'm not sure where the second camera, or viewport is supposed to be? Rotate the camera?

Is the interior merely a bitmap image? I'm not sure what your trying to achieve :o)

If you are copyrecting, you can stagger this across two frames, by copying the bottom half, then the top half alternately. Or, have a look at the fast extend lib, where render-to-texture is available.


jfk EO-11110(Posted 2009) [#8]
I assume you want something like this: Player is in room A with a surveillance monitor that is connetcted with a surveillance camera in room B.
IN fact you only have to create a camera at the camera-meshes position. Then you do it this way:

...
turn off camera a (using cameraprojmode !)
turn on camera B
renderworld (only the 256 pixels)
copyrect to texturebuffer
turn off camera B
turn on camera A
renderworld as usual
flip

As Ross said: use the VRam flag for this texture. Also make sure the cameraviewport is only eg. 256*256, esp. if the user won't see the virtual monitor much larger onscreen. Then it may also be an option to update only about 12 times a second, this is about original walt disney cartoons framerate. Copy-to-texture is the main bottle neck. Hint: a very small texture size will look much better when you add some kind of interlace effect (eg. erase every 2nd line).

Note right after the first renderworld you may add some fx to the render, like snow storm, screen distortion or inconsistent transmission quality artefacts.

It is a nice feature to use a camera as a real camera in the world, I've seen this in many nice games, especially NOLF, where I hate the missions that force you to stay hidden trough the entire level... :)


Santiworld(Posted 2009) [#9]
thanks :)..

i need the two options... and this information is very usefull.

i go to try now, to see if i can do it.

regards....
santiago

(sorry my english)


_PJ_(Posted 2009) [#10]
It depends... if the "monitor" is just a flat square on the screen, he can get away just making a new viewport, but if it moves, if it's tilted somehow or can be viewed from more than one static pov, then there's no way other than rendering it to a texture and using that texture on a 3d model.

Too bad B3D doesn't have a direct render to texture, and we have to use this Copyrect trick...



Ah yeah I didnt think of that. It sure would help having Render to Image or Texture functionality sure.


Santiworld(Posted 2009) [#11]
hi again, i working to improve the LCD screens of the inside car..
i post part of the code i use for my game, to made the screen data change in the realtime when you drive the car..

i use SpeedText Library for Blitz3D for my text..

the texture is created, but the fps of the game are reduce

how can i improve this code to increase the FPS...
i have something wrong in the code?

thanks...





;start game


	
	graphics3d 1024,768,32,1
 	st_initialize(backbuffer())
	frametimer = CreateTimer(60)	
	If startlogomode = 1 Then startlogo()
	SetBuffer BackBuffer()

	global plan_cam	
	global t_lcd1=CreateTexture( 128,128,256,1 ) ;VRAM
        global lcd1 =  findchild(interior,"lcd1mesh")
	entitycolor lcd1,255,255,255
	entityfx lcd1,2
	EntityTexture lcd1,t_lcd1,0,1
	textureblend t_lcd1,5
	
	global t_lcd2=CreateTexture( 128,128,256,1 );VRAM
        global lcd2 =  findchild(interior,"lcd2mesh")
	entitycolor lcd2,255,255,255
	entityfx lcd2,2
	EntityTexture lcd2,t_lcd2,0,1
  textureblend t_lcd2,5
  
	create_plan_cam()

while not keyhit(1)

  ;game loop data
	
    WaitTimer(frametimer)
    updateworld()
    renderworld(twin)
  ;2d data

    Flip false

 
  if vista=2 then   ;if the camera is in the inside of the car
   redraw_lcd1()    ;go to draw lcd functions
   redraw_lcd2()
  endif 

wend  ;end game loop

function create_plan_cam()	
	plan_cam=CreateCamera()
	TurnEntity plan_cam,90,0,0
	PositionEntity plan_cam,0,20,0
	CameraViewport plan_cam,0,0,128,128
	CameraClsColor plan_cam,0,128,0
	cameraprojmode plan_cam,0
	end function




this is the function i use to draw the lcd2 data


function redraw_lcd2()

	cameraprojmode cam,0
	cameraprojmode plan_cam,2
	color 100,100,100
	rect 0,0,128,128
	st_setfont font_lcd2
	st_textcolor 255,255,255
	st_drawtext 10,10, "Pos    : " +pos(1)+"/"+coches,st_left,st_top
	st_drawtext 10,30, "Laps  :" +laps(1)+"/"+vueltas,st_left,st_top
	st_drawtext 10,60, "Time  "+ t_hor(1)+":"+t_min(1)+":"+t_sec(1)+":"+t_cen(1),st_left,st_top
	st_drawtext 10,80, "Last  "+ tl_hor(1)+":"+tl_min(1)+":"+tl_sec(1)+":"+tl_cen(1),st_left,st_top
	st_drawtext 10,100,"Best  "+ tb_hor(1)+":"+tb_min(1)+":"+tb_sec(1)+":"+tb_cen(1),st_left,st_top
	
	
	CopyRect 0,0,128,128,0,0,0,TextureBuffer( t_lcd2 )
	cameraprojmode cam,1
	cameraprojmode plan_cam,0

	end function




Stevie G(Posted 2009) [#12]
I have no idea how fast text works so cannot comment on that. Copyrect can be slow. Suggest that you just update the LCD hud text every second or 3rd frame.


Ross C(Posted 2009) [#13]
Did you try the fast extend libs? They will do what you need and alot faster.


Santiworld(Posted 2009) [#14]
hi, for the moment, i did what stevie said, i refresh the LCD every 10 frames.

i haven't seen the fast extend libs, i'm going to research about that library.

thanks !.


Adam Novagen(Posted 2009) [#15]
I tried the FastExtend demo recently, but couldn't get it working. I put the correct DECLS in their respective places, and the commands were put in Blitz's compiler just fine, but every time I tried to run a program with the FE demo (including the samples it came with,) I kept getting an "Unknown Runtime Exception." Whuh??? Any idea what that was?


Ross C(Posted 2009) [#16]
I'm afraid i have no idea... :o(


Santiworld(Posted 2009) [#17]
i found a good product when i buy jv-ode, because vip3r allways answer very fast in this forum.. that is a very good thing.

the fasttext i use is a free lib, is simple and good...

who made the fast extend lib?..
FastExtend is a good option?, i mean, price, and support?

i go to find the demo to try it..


lo-tekk(Posted 2009) [#18]
Here's the last Fast Extend library thread:
http://www.blitzbasic.com/Community/posts.php?topic=81671


ardee(Posted 2009) [#19]
@Adam Novagen

I get the "Unknown Runtime Exception" when compiling with Blitz3D v1.100 but it works fine if you downgrade to Blitz3D v1.99.


Adam Novagen(Posted 2009) [#20]
Oh... Crud... I hate downgrades. T_T

Ah well, I'll look into it. Thanks ardee!