CCTexture2D Class Reference
Inherits from | NSObject |
Declared in | CCTexture2D.h |
Overview
CCTexture2D class. This class allows to easily create OpenGL 2D textures from images, text or raw data. The created CCTexture2D object will always have power-of-two dimensions. Depending on how you create the CCTexture2D object, the actual image area of the texture might be smaller than the texture dimensions i.e. “contentSize” != (pixelsWide, pixelsHigh) and (maxS, maxT) != (1.0, 1.0). Be aware that the content of the generated textures will be upside-down!
Drawing extensions to make it easy to draw basic quads using a CCTexture2D object. These functions require GL_TEXTURE_2D and both GL_VERTEX_ARRAY and GL_TEXTURE_COORD_ARRAY client states to be enabled.
Extensions to make it easy to create a CCTexture2D object from a string of text. Note that the generated textures are of type A8 – use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
Extensions to make it easy to create a CCTexture2D object from a PVRTC file Note that the generated textures don’t have their alpha premultiplied – use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
Extension to set the Min / Mag filter
Extensions to make it easy to create a CCTexture2D object from an image file. Note that RGBA type textures will have their alpha premultiplied – use the blending mode (GL_ONE, GL_ONE_MINUS_SRC_ALPHA).
Extensions to make it easy to create a CCTexture2D object from a PVRTC file Note that the generated textures don’t have their alpha premultiplied – use the blending mode (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA).
Tasks
Other Methods
-
– initWithData:pixelFormat:pixelsWide:pixelsHigh:contentSize:
Initializes with a texture2d with data
-
– releaseData:
These functions are needed to create mutable textures
-
– keepData:length:
-
pixelFormat
pixel format of the texture
property -
pixelsWide
width in pixels
property -
pixelsHigh
hight in pixels
property -
name
texture name
property -
contentSizeInPixels
returns content size of the texture in pixels
property -
maxS
texture max S
property -
maxT
texture max T
property -
hasPremultipliedAlpha
whether or not the texture has their Alpha premultiplied
property -
shaderProgram
shader program used by drawAtPoint and drawInRect
property -
resolutionType
Returns the resolution type of the texture. Is it a RetinaDisplay texture, an iPad texture, a Mac, a Mac RetinaDisplay or an standard texture ?
property -
– contentSize
returns the content size of the texture in points
Drawing Methods
-
– drawAtPoint:
draws a texture at a given point
-
– drawInRect:
draws a texture inside a rect
Text Methods
-
– initWithString:fontName:fontSize:dimensions:hAlignment:vAlignment:lineBreakMode:
Initializes a texture from a string with dimensions, alignment, line break mode, font name and font size Supported lineBreakModes:
- iOS: all UILineBreakMode supported modes - Mac: Only NSLineBreakByWordWrapping is supported.
-
– initWithString:fontName:fontSize:dimensions:hAlignment:vAlignment:
Initializes a texture from a string with dimensions, alignment, font name and font size
-
– initWithString:fontName:fontSize:
Initializes a texture from a string with font name and font size
-
– initWithString:dimensions:alignment:fontName:fontSize:
Initializes a texture from a string with dimensions, alignment, font name and font size
PVRTC Methods
-
– initWithPVRTCData:level:bpp:hasAlpha:length:
Initializes a texture from a PVRTC buffer
-
– initWithPVRTCFile:
Initializes a texture from a PVRTC file
GLFilter Methods
-
– setTexParameters:
sets the min filter, mag filter, wrap s and wrap t texture parameters. If the texture size is NPOT (non power of 2), then in can only use GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}.
-
– setAntiAliasTexParameters
sets antialias texture parameters: – GL_TEXTURE_MIN_FILTER = GL_LINEAR – GL_TEXTURE_MAG_FILTER = GL_LINEAR
-
– setAliasTexParameters
sets alias texture parameters: – GL_TEXTURE_MIN_FILTER = GL_NEAREST – GL_TEXTURE_MAG_FILTER = GL_NEAREST
-
– generateMipmap
Generates mipmap images for the texture. It only works if the texture size is POT (power of 2).
PixelFormat Methods
-
+ setDefaultAlphaPixelFormat:
sets the default pixel format for CGImages that contains alpha channel. If the CGImage contains alpha channel, then the options are:
- generate 32-bit textures: kCCTexture2DPixelFormat_RGBA8888 (default one) - generate 16-bit textures: kCCTexture2DPixelFormat_RGBA4444 - generate 16-bit textures: kCCTexture2DPixelFormat_RGB5A1 - generate 24-bit textures: kCCTexture2DPixelFormat_RGB888 (no alpha) - generate 16-bit textures: kCCTexture2DPixelFormat_RGB565 (no alpha) - generate 8-bit textures: kCCTexture2DPixelFormat_A8 (only use it if you use just 1 color)
-
+ defaultAlphaPixelFormat
returns the alpha pixel format
-
– bitsPerPixelForFormat
returns the bits-per-pixel of the in-memory OpenGL texture
-
– stringForFormat
returns the pixel format in a NSString.
-
+ bitsPerPixelForFormat:
Helper functions that returns bits per pixels for a given format.
Image Methods
-
– initWithCGImage:resolutionType:
Initializes a texture from a CGImage object
-
– initWithImage:
Initializes a texture from a UIImage object
PVRSupport Methods
-
– initWithPVRFile:
Initializes a texture from a PVR file.
-
+ PVRImagesHavePremultipliedAlpha:
treats (or not) PVR files as if they have alpha premultiplied. Since it is impossible to know at runtime if the PVR images have the alpha channel premultiplied, it is possible load them as if they have (or not) the alpha channel premultiplied.
Extension Methods
Deprecated Methods
Properties
contentSizeInPixels
returns content size of the texture in pixels
@property (nonatomic, readonly, nonatomic) CGSize contentSizeInPixels
Declared In
CCTexture2D.h
hasPremultipliedAlpha
whether or not the texture has their Alpha premultiplied
@property (nonatomic, readonly) BOOL hasPremultipliedAlpha
Declared In
CCTexture2D.h
pixelFormat
pixel format of the texture
@property (nonatomic, readonly) CCTexture2DPixelFormat pixelFormat
Declared In
CCTexture2D.h
pixelsHigh
hight in pixels
@property (nonatomic, readonly) NSUInteger pixelsHigh
Declared In
CCTexture2D.h
pixelsWide
width in pixels
@property (nonatomic, readonly) NSUInteger pixelsWide
Declared In
CCTexture2D.h
resolutionType
Returns the resolution type of the texture. Is it a RetinaDisplay texture, an iPad texture, a Mac, a Mac RetinaDisplay or an standard texture ?
@property (nonatomic, readwrite) ccResolutionType resolutionType
Availability
Discussion
Should be a readonly property. It is readwrite as a hack.
Declared In
CCTexture2D.h
Class Methods
PVRImagesHavePremultipliedAlpha:
treats (or not) PVR files as if they have alpha premultiplied. Since it is impossible to know at runtime if the PVR images have the alpha channel premultiplied, it is possible load them as if they have (or not) the alpha channel premultiplied.
+ (void)PVRImagesHavePremultipliedAlpha:(BOOL)haveAlphaPremultiplied
Availability
Discussion
By default it is disabled.
Declared In
CCTexture2D.h
bitsPerPixelForFormat:
Helper functions that returns bits per pixels for a given format.
+ (NSUInteger)bitsPerPixelForFormat:(CCTexture2DPixelFormat)format
Availability
Declared In
CCTexture2D.h
defaultAlphaPixelFormat
returns the alpha pixel format
+ (CCTexture2DPixelFormat)defaultAlphaPixelFormat
Availability
Declared In
CCTexture2D.h
setDefaultAlphaPixelFormat:
sets the default pixel format for CGImages that contains alpha channel. If the CGImage contains alpha channel, then the options are:
- generate 32-bit textures: kCCTexture2DPixelFormat_RGBA8888 (default one)
- generate 16-bit textures: kCCTexture2DPixelFormat_RGBA4444
- generate 16-bit textures: kCCTexture2DPixelFormat_RGB5A1
- generate 24-bit textures: kCCTexture2DPixelFormat_RGB888 (no alpha)
- generate 16-bit textures: kCCTexture2DPixelFormat_RGB565 (no alpha)
- generate 8-bit textures: kCCTexture2DPixelFormat_A8 (only use it if you use just 1 color)
+ (void)setDefaultAlphaPixelFormat:(CCTexture2DPixelFormat)format
Availability
Discussion
How does it work ? – If the image is an RGBA (with Alpha) then the default pixel format will be used (it can be a 8-bit, 16-bit or 32-bit texture) – If the image is an RGB (without Alpha) then: If the default pixel format is RGBA8888 then a RGBA8888 (32-bit) will be used. Otherwise a RGB565 (16-bit texture) will be used.
This parameter is not valid for PVR / PVR.CCZ images.
Declared In
CCTexture2D.h
Instance Methods
bitsPerPixelForFormat
returns the bits-per-pixel of the in-memory OpenGL texture
- (NSUInteger)bitsPerPixelForFormat
Availability
Declared In
CCTexture2D.h
contentSize
returns the content size of the texture in points
- (CGSize)contentSize
Declared In
CCTexture2D.h
drawAtPoint:
draws a texture at a given point
- (void)drawAtPoint:(CGPoint)point
Declared In
CCTexture2D.h
generateMipmap
Generates mipmap images for the texture. It only works if the texture size is POT (power of 2).
- (void)generateMipmap
Availability
Declared In
CCTexture2D.h
initWithCGImage:resolutionType:
Initializes a texture from a CGImage object
- (id)initWithCGImage:(CGImageRef)cgImage resolutionType:(ccResolutionType)resolution
Declared In
CCTexture2D.h
initWithData:pixelFormat:pixelsWide:pixelsHigh:contentSize:
Initializes with a texture2d with data
- (id)initWithData:(const void *)data pixelFormat:(CCTexture2DPixelFormat)pixelFormat pixelsWide:(NSUInteger)width pixelsHigh:(NSUInteger)height contentSize:(CGSize)size
Declared In
CCTexture2D.h
initWithImage:
Initializes a texture from a UIImage object
- (id)initWithImage:(UIImage *)uiImage
Declared In
CCTexture2D.h
initWithPVRFile:
Initializes a texture from a PVR file.
- (id)initWithPVRFile:(NSString *)file
Discussion
Supported PVR formats: – BGRA 8888 – RGBA 8888 – RGBA 4444 – RGBA 5551 – RBG 565 – A 8 – I 8 – AI 8 – PVRTC 2BPP – PVRTC 4BPP
By default PVR images are treated as if they alpha channel is NOT premultiplied. You can override this behavior with this class method: – PVRImagesHavePremultipliedAlpha:(BOOL)haveAlphaPremultiplied;
IMPORTANT: This method is only defined on iOS. It is not supported on the Mac version.
Declared In
CCTexture2D.h
initWithPVRTCData:level:bpp:hasAlpha:length:
Initializes a texture from a PVRTC buffer
- (id)initWithPVRTCData:(const void *)data level:(int)level bpp:(int)bpp hasAlpha:(BOOL)hasAlpha length:(int)length
Declared In
CCTexture2D.h
initWithPVRTCFile:
Initializes a texture from a PVRTC file
- (id)initWithPVRTCFile:(NSString *)file
Declared In
CCTexture2D.h
initWithString:dimensions:alignment:fontName:fontSize:
Initializes a texture from a string with dimensions, alignment, font name and font size
- (id)initWithString:(NSString *)string dimensions:(CGSize)dimensions alignment:(UITextAlignment)alignment fontName:(NSString *)name fontSize:(CGFloat)size
Declared In
CCTexture2D.h
initWithString:fontName:fontSize:
Initializes a texture from a string with font name and font size
- (id)initWithString:(NSString *)string fontName:(NSString *)name fontSize:(CGFloat)size
Declared In
CCTexture2D.h
initWithString:fontName:fontSize:dimensions:hAlignment:vAlignment:
Initializes a texture from a string with dimensions, alignment, font name and font size
- (id)initWithString:(NSString *)string fontName:(NSString *)name fontSize:(CGFloat)size dimensions:(CGSize)dimensions hAlignment:(CCTextAlignment)alignment vAlignment:(CCVerticalTextAlignment)vertAlignment
Declared In
CCTexture2D.h
initWithString:fontName:fontSize:dimensions:hAlignment:vAlignment:lineBreakMode:
Initializes a texture from a string with dimensions, alignment, line break mode, font name and font size Supported lineBreakModes:
- iOS: all UILineBreakMode supported modes
- Mac: Only NSLineBreakByWordWrapping is supported.
- (id)initWithString:(NSString *)string fontName:(NSString *)name fontSize:(CGFloat)size dimensions:(CGSize)dimensions hAlignment:(CCTextAlignment)alignment vAlignment:(CCVerticalTextAlignment)vertAlignment lineBreakMode:(CCLineBreakMode)lineBreakMode
Availability
Declared In
CCTexture2D.h
releaseData:
These functions are needed to create mutable textures
- (void)releaseData:(void *)data
Declared In
CCTexture2D.h
setAliasTexParameters
sets alias texture parameters: – GL_TEXTURE_MIN_FILTER = GL_NEAREST – GL_TEXTURE_MAG_FILTER = GL_NEAREST
- (void)setAliasTexParameters
Availability
Discussion
Warning: Calling this method could allocate additional texture memory.
Declared In
CCTexture2D.h
setAntiAliasTexParameters
sets antialias texture parameters: – GL_TEXTURE_MIN_FILTER = GL_LINEAR – GL_TEXTURE_MAG_FILTER = GL_LINEAR
- (void)setAntiAliasTexParameters
Availability
Discussion
Warning: Calling this method could allocate additional texture memory.
Declared In
CCTexture2D.h
setTexParameters:
sets the min filter, mag filter, wrap s and wrap t texture parameters. If the texture size is NPOT (non power of 2), then in can only use GL_CLAMP_TO_EDGE in GL_TEXTURE_WRAP_{S,T}.
- (void)setTexParameters:(ccTexParams *)texParams
Availability
Discussion
Warning: Calling this method could allocate additional texture memory.
Declared In
CCTexture2D.h