SetRenderToImage

Description

Redirects all future draw calls to an image instead of to the screen. The specified image could then be applied to an object or sprite. Be careful not to apply to an object or sprite at the same time as it is being drawn to as this could result in an error. You can also choose to render the depth information to an image that you can use later, or render without a depth buffer if your scene does not need one. You can also use a depth image ID of -1 to render a depth buffer without capturing it in an image. Note that some devices (particularly Android) do not support rendering depth to an image, in these cases the only valid values for the depth ID are 0 and -1. You can check if the current device supports depth textures by using IsSupportedDepthTexture. Render images can be any size, and do not need to be a power of 2 in width or height.

For a more detailed explanation, when you render to an image it will draw to the image exactly what it would have drawn to the screen. For example if your virtual resolution is 1024x768 and requires borders then it will draw borders onto the render image. This means if you were to look at the resulting render image in its native form, e.g. 1024x1024, it will look like you've taken a 1024x768 window and stretched it vertically into a square. The result is that if you take this square image and stretch it back into 1024x768, by texturing a sprite or quad that happens to be 1024x768 in size, then it will look normal again. This means you can render a 1024x768 window to an image of any size, say 64x512, and stretch it to 1024x768 and it should look correct aspect ratio wise, it will of course be missing some detail. You can then get more advanced by changing the virtual resolution after setting a render image and changing it back when rendering to the screen, or using SetCameraAspect to change the 3D aspect ratio if the render image is going to be used for something other than a 1:1 representation of the screen.

When rendering to an image it is very important that the image be cleared with ClearScreen() before drawing a new scene to it. This is so the GPU knows it can discard the previous contents. If the image is not cleared and things keep getting drawn to it then performance on some GPUs will degrade over time.

Definition

SetRenderToImage( colorImage, depthImage )

Parameters