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 the image 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.

After calling SetRenderToImage the image contents is undefined and can be cleared with ClearScreen, however if you are going to draw to every pixel on the screen, such as with a full screen shader then this is not necessary. It is not possible to call SetRenderToImage multiple times with the same image to add more drawn items to the image, the image will always become undefined after the call to SetRenderToImage. If you wish to maintain the contents of a previous render then you should render to a new image and apply the previously rendered image to a quad to draw it as a background. You can then swap the images in the next frame to continuously render the previous frame as a background to the current frame.

Definition

SetRenderToImage( colorImage, depthImage )

Parameters