Render to Texture

Another nice new feature X3D V2 holds is the ability to render a camera onto an object as a texture. This method can achieve many effects such as putting animated characters or scenes on a television or screen, a portal effect, and many more. You may have seen this effect in games such as Half-Life 2. I'm expanding on the example that comes with X3D V2 name X4.gm6.
First thing that we do is open up o_engine.
In the Create event add this line of code:
//creates a material to apply to the object
MaterialCreate('mscene',' ');
I am now going to create a cube to apply the material to:
//creates a object that the material will be applied to
cube=CubeCreate(8,8,8,scene);
ObjectSetPosition(cube,0,0,0);
ObjectSetMaterial(cube,'mscene');
alarm[0]=1;
You now create the camera:
cam=CameraCreate(scene);
ObjectSetPosition(cam,0,0,0);
CameraSetFocal(cam,50);
Create Alarm 0 event and add this in there:
if ObjectInFrustrum(cube)
{
ObjectHide(cube);
CameraCopyToTexture(cam,'mscene',256,256);
ObjectShow(cube);
} //this alarm sets how long it will take to update the image
alarm[0]=6;
All there is left is to put the objects you wish to see on the texture in front of the camera. you may place the objects anywhere you want (most of the time it would be in a place often unreachable by the player)
Downloads