diff options
Diffstat (limited to 'libs/cocos2d/CCRenderTexture.h')
| -rwxr-xr-x | libs/cocos2d/CCRenderTexture.h | 108 |
1 files changed, 108 insertions, 0 deletions
| diff --git a/libs/cocos2d/CCRenderTexture.h b/libs/cocos2d/CCRenderTexture.h new file mode 100755 index 0000000..d5e39cc --- /dev/null +++ b/libs/cocos2d/CCRenderTexture.h | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | /* | ||
| 2 | * cocos2d for iPhone: http://www.cocos2d-iphone.org | ||
| 3 | * | ||
| 4 | * Copyright (c) 2009 Jason Booth | ||
| 5 | * | ||
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 7 | * of this software and associated documentation files (the "Software"), to deal | ||
| 8 | * in the Software without restriction, including without limitation the rights | ||
| 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
| 10 | * copies of the Software, and to permit persons to whom the Software is | ||
| 11 | * furnished to do so, subject to the following conditions: | ||
| 12 | * | ||
| 13 | * The above copyright notice and this permission notice shall be included in | ||
| 14 | * all copies or substantial portions of the Software. | ||
| 15 | * | ||
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
| 22 | * THE SOFTWARE. | ||
| 23 | * | ||
| 24 | */ | ||
| 25 | |||
| 26 | #import <Foundation/Foundation.h> | ||
| 27 | #import "CCNode.h" | ||
| 28 | #import "CCSprite.h" | ||
| 29 | #import "Support/OpenGL_Internal.h" | ||
| 30 | |||
| 31 | #import <Availability.h> | ||
| 32 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED | ||
| 33 | #import <UIKit/UIKit.h> | ||
| 34 | #endif // iPHone | ||
| 35 | |||
| 36 | enum | ||
| 37 | { | ||
| 38 | kCCImageFormatJPG = 0, | ||
| 39 | kCCImageFormatPNG = 1, | ||
| 40 | kCCImageFormatRawData =2 | ||
| 41 | }; | ||
| 42 | |||
| 43 | |||
| 44 | /** | ||
| 45 | CCRenderTexture is a generic rendering target. To render things into it, | ||
| 46 | simply construct a render target, call begin on it, call visit on any cocos | ||
| 47 | scenes or objects to render them, and call end. For convienience, render texture | ||
| 48 | adds a sprite as it's display child with the results, so you can simply add | ||
| 49 | the render texture to your scene and treat it like any other CocosNode. | ||
| 50 | There are also functions for saving the render texture to disk in PNG or JPG format. | ||
| 51 | |||
| 52 | @since v0.8.1 | ||
| 53 | */ | ||
| 54 | @interface CCRenderTexture : CCNode | ||
| 55 | { | ||
| 56 | GLuint fbo_; | ||
| 57 | GLint oldFBO_; | ||
| 58 | CCTexture2D* texture_; | ||
| 59 | CCSprite* sprite_; | ||
| 60 | |||
| 61 | GLenum pixelFormat_; | ||
| 62 | } | ||
| 63 | |||
| 64 | /** The CCSprite being used. | ||
| 65 | The sprite, by default, will use the following blending function: GL_ONE, GL_ONE_MINUS_SRC_ALPHA. | ||
| 66 | The blending function can be changed in runtime by calling: | ||
| 67 | - [[renderTexture sprite] setBlendFunc:(ccBlendFunc){GL_ONE, GL_ONE_MINUS_SRC_ALPHA}]; | ||
| 68 | */ | ||
| 69 | @property (nonatomic,readwrite, assign) CCSprite* sprite; | ||
| 70 | |||
| 71 | /** creates a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */ | ||
| 72 | +(id)renderTextureWithWidth:(int)w height:(int)h pixelFormat:(CCTexture2DPixelFormat) format; | ||
| 73 | |||
| 74 | /** creates a RenderTexture object with width and height in Points, pixel format is RGBA8888 */ | ||
| 75 | +(id)renderTextureWithWidth:(int)w height:(int)h; | ||
| 76 | |||
| 77 | /** initializes a RenderTexture object with width and height in Points and a pixel format, only RGB and RGBA formats are valid */ | ||
| 78 | -(id)initWithWidth:(int)w height:(int)h pixelFormat:(CCTexture2DPixelFormat) format; | ||
| 79 | |||
| 80 | /** starts grabbing */ | ||
| 81 | -(void)begin; | ||
| 82 | |||
| 83 | /** starts rendering to the texture while clearing the texture first. | ||
| 84 | This is more efficient then calling -clear first and then -begin */ | ||
| 85 | -(void)beginWithClear:(float)r g:(float)g b:(float)b a:(float)a; | ||
| 86 | |||
| 87 | /** ends grabbing */ | ||
| 88 | -(void)end; | ||
| 89 | |||
| 90 | /** clears the texture with a color */ | ||
| 91 | -(void)clear:(float)r g:(float)g b:(float)b a:(float)a; | ||
| 92 | |||
| 93 | #ifdef __IPHONE_OS_VERSION_MAX_ALLOWED | ||
| 94 | |||
| 95 | /** saves the texture into a file */ | ||
| 96 | -(BOOL)saveBuffer:(NSString*)name; | ||
| 97 | /** saves the texture into a file. The format can be JPG or PNG */ | ||
| 98 | -(BOOL)saveBuffer:(NSString*)name format:(int)format; | ||
| 99 | /* get buffer as UIImage, can only save a render buffer which has a RGBA8888 pixel format */ | ||
| 100 | -(NSData*)getUIImageAsDataFromBuffer:(int) format; | ||
| 101 | /* get buffer as UIImage */ | ||
| 102 | -(UIImage *)getUIImageFromBuffer; | ||
| 103 | |||
| 104 | #endif // __IPHONE_OS_VERSION_MAX_ALLOWED | ||
| 105 | |||
| 106 | @end | ||
| 107 | |||
| 108 | |||
