代码:
/**
* @brief RenderTexture is a generic rendering target. To render things into it,
* simply construct a render target, call begin on it, call visit on any cocos
* scenes or objects to render them, and call end. For convenience, render texture
* adds a sprite as it's display child with the results, so you can simply add
* the render texture to your scene and treat it like any other CocosNode.
* There are also functions for saving the render texture to disk in PNG or JPG format.
* @since v0.8.1
*/
// RenderTexture是一个通用的渲染目标。为了将目标渲染到其中,只需要构造一个渲染目标,调用它的begin方法
// 然后调用对象的visit方法来渲染他们,调用end方法结束。为了方便,RenderTexture添加一个精灵显示节点作为结果。
//所以,你只需要将render Texture添加到你的场景,像对待其他cocosNode一样对待他就行了。
// 也有将图片按png,jpg格式存储到硬盘的方法
class CC_DLL RenderTexture : public Node
{
public:
/** Initializes a RenderTexture object with width and height in Points and a pixel format( only RGB and RGBA formats are valid ) and depthStencil format.
*
* @param w The RenderTexture object width.
* @param h The RenderTexture object height.
* @param format In Points and a pixel format( only RGB and RGBA formats are valid ).
* @param depthStencilFormat The depthStencil format.
*/
// 创建一个RederTexture
static RenderTexture * create(int w ,int h, Texture2D::PixelFormat format, GLuint depthStencilFormat);
/** Creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid.
*
* @param w The RenderTexture object width.
* @param h The RenderTexture object height.
* @param format In Points and a pixel format( only RGB and RGBA formats are valid ).
*/
static RenderTexture * create(int w, int h, Texture2D::PixelFormat format);
/** Creates a RenderTexture object with width and height in Points, pixel format is RGBA8888.
*
* @param w The RenderTexture object width.
* @param h The RenderTexture object height.
*/
static RenderTexture * create(int w, int h);
/** Starts grabbing. */
// 开始获取
virtual void begin();
/** Starts rendering to the texture while clearing the texture first.
* This is more efficient then calling -clear first and then -begin.
*
* @param r Red.
* @param g Green.
* @param b Blue.
* @param a Alpha.
*/
// 在开始前 清除颜色
virtual void beginWithClear(float r, float g, float b, float a);
/** Starts rendering to the texture while clearing the texture first.