SetCameraToTexture

From ZDoom Wiki
Jump to: navigation, search

void SetCameraToTexture(int cameratid, str texturename, int fov);

Usage

Binds the named texture to the specified camera (which does not have to be an actual camera thing). From this point on, whatever the camera sees in the specified FOV will be drawn onto the specified texture every frame. Apparently, there is no way to "unbind" the texture, but it can be bound to a different camera.

Camera textures are only recalculated when they are viewed. Therefore, you may make liberal use of camera textures, as long as there are not several on-screen at once.

Note that the texture used must be defined as a “cameratexture” in the ANIMDEFS lump.

Examples

Sample ANIMDEFS entry:

cameratexture TCAMTEX1 128 64 fit 80 56

This will make available a texture called “TCAMTEX1”, 80 pixels wide and 56 high (but with a slightly higher, horizontally-compressed resolution), that can be applied to any wall or set of walls in a map. Next, a camera thing is put in an interesting spot in the map and is given a TID (7 in this example). Afterwards, paste the following in the map's ACS script:

 script 1 OPEN {
   SetCameraToTexture( 7, "TCAMTEX1", 90 );
 }

Now, all surfaces with TCAMTEX1 on them will be video screens showing what the camera with TID 7 sees. One could re-assign the texture to a different camera with a trigger somewhere in the level:

 script 2 (int camera_tid, int fov) {
   SetCameraToTexture( camera_tid, "TCAMTEX1", fov );
 }

Triggered by walk-over lines, this would allow to re-use the same camera texture over and over again at different points in the level, possibly saving a bit of memory and lines in ANIMDEFS. Another use is to have a script that periodically changes the screen's view:

 script 3 OPEN {
   int inter_delay = 70; // 2 seconds between switching
   while( TRUE ) {
     SetCameraToTexture( 7, "TCAMTEX1", 90 );
     Delay( inter_delay );
     SetCameraToTexture( 12, "TCAMTEX1", 90 );
     Delay( inter_delay );
     SetCameraToTexture( 15, "TCAMTEX1", 40 ); // this one's zoomed in!
     Delay( inter_delay );
   }
 }