cocos2d-iphone  1.1
Improved Cocos2D API Reference (iOS version) for www.kobold2d.com developers
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Properties Defines
CCTexture2D Class Reference

#import <CCTexture2D.h>

List of all members.

Public Member Functions

(id) - initWithData:pixelFormat:pixelsWide:pixelsHigh:contentSize:
(void) - releaseData:
(void *) - keepData:length:
(CGSize) - contentSize
(void) - drawAtPoint:
(void) - drawInRect:
(void) - setTexParameters:
(void) - setAntiAliasTexParameters
(void) - setAliasTexParameters
(void) - generateMipmap
(id) - initWithImage:resolutionType:
(id) - initWithImage:
(NSUInteger) - bitsPerPixelForFormat
(id) - initWithPVRTCData:level:bpp:hasAlpha:length:pixelFormat:
(id) - initWithPVRFile:
(id) - initWithString:dimensions:alignment:lineBreakMode:fontName:fontSize:
(id) - initWithString:dimensions:alignment:fontName:fontSize:
(id) - initWithString:fontName:fontSize:

Static Public Member Functions

(void) + setDefaultAlphaPixelFormat:
(CCTexture2DPixelFormat) + defaultAlphaPixelFormat
(void) + PVRImagesHavePremultipliedAlpha:

Protected Attributes

GLuint name_
CGSize size_
NSUInteger width_
NSUInteger height_
CCTexture2DPixelFormat format_
GLfloat maxS_
GLfloat maxT_
BOOL hasPremultipliedAlpha_
ccResolutionType resolutionType_

Properties

CCTexture2DPixelFormat pixelFormat
NSUInteger pixelsWide
NSUInteger pixelsHigh
GLuint name
CGSize contentSizeInPixels
GLfloat maxS
GLfloat maxT
BOOL hasPremultipliedAlpha
ccResolutionType resolutionType

Detailed Description

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!


Member Function Documentation

- (NSUInteger) bitsPerPixelForFormat

returns the bits-per-pixel of the in-memory OpenGL texture

Since:
v1.0
- (CGSize) contentSize

returns the content size of the texture in points

+ (CCTexture2DPixelFormat) defaultAlphaPixelFormat

returns the alpha pixel format

Since:
v0.8
- (void) drawAtPoint: (CGPoint)  point

draws a texture at a given point

- (void) drawInRect: (CGRect)  rect

draws a texture inside a rect

- (void) generateMipmap

Generates mipmap images for the texture. It only works if the texture size is POT (power of 2).

Since:
v0.99.0
- (id) initWithData: (const void *)  data
pixelFormat: (CCTexture2DPixelFormat)  pixelFormat
pixelsWide: (NSUInteger)  width
pixelsHigh: (NSUInteger)  height
contentSize: (CGSize)  size 

Intializes with a texture2d with data

- (id) initWithImage: (UIImage *)  uiImage
resolutionType: (ccResolutionType resolution 

Initializes a texture from a UIImage object

- (id) initWithPVRFile: (NSString *)  file

Initializes a texture from a PVR file.

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:

IMPORTANT: This method is only defined on iOS. It is not supported on the Mac version.

- (id) initWithPVRTCData: (const void *)  data
level: (int)  level
bpp: (int)  bpp
hasAlpha: (BOOL)  hasAlpha
length: (int)  length
pixelFormat: (CCTexture2DPixelFormat)  pixelFormat 

Initializes a texture from a PVR Texture Compressed (PVRTC) buffer

IMPORTANT: This method is only defined on iOS. It is not supported on the Mac version.

Deprecated:
Use initWithPVRFile instead. Will be removed in 2.0
- (id) initWithString: (NSString *)  string
dimensions: (CGSize)  dimensions
alignment: (CCTextAlignment)  alignment
fontName: (NSString *)  name
fontSize: (CGFloat)  size 

Initializes a texture from a string with dimensions, alignment, font name and font size

- (id) initWithString: (NSString *)  string
dimensions: (CGSize)  dimensions
alignment: (CCTextAlignment)  alignment
lineBreakMode: (CCLineBreakMode)  lineBreakMode
fontName: (NSString *)  name
fontSize: (CGFloat)  size 

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.
    Since:
    v1.0
- (id) initWithString: (NSString *)  string
fontName: (NSString *)  name
fontSize: (CGFloat)  size 

Initializes a texture from a string with font name and font size

+ (void) PVRImagesHavePremultipliedAlpha: (BOOL)  haveAlphaPremultiplied

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.

By default it is disabled.

Since:
v0.99.5
- (void) releaseData: (void *)  data

These functions are needed to create mutable textures

sets alias texture parameters:

  • GL_TEXTURE_MIN_FILTER = GL_NEAREST
  • GL_TEXTURE_MAG_FILTER = GL_NEAREST
Since:
v0.8

sets antialias texture parameters:

  • GL_TEXTURE_MIN_FILTER = GL_LINEAR
  • GL_TEXTURE_MAG_FILTER = GL_LINEAR
Since:
v0.8
+ (void) setDefaultAlphaPixelFormat: (CCTexture2DPixelFormat)  format

sets the default pixel format for UIImages that contains alpha channel. If the UIImage 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 16-bit textures: kCCTexture2DPixelFormat_RGB565
  • generate 8-bit textures: kCCTexture2DPixelFormat_A8 (only use it if you use just 1 color)

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 an RGB565 texture will be used (16-bit texture)

This parameter is not valid for PVR images.

Since:
v0.8
- (void) setTexParameters: (ccTexParams *)  texParams

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}.

Since:
v0.8

Property Documentation

- (CGSize) contentSizeInPixels [read, assign]

returns content size of the texture in pixels

- (BOOL) hasPremultipliedAlpha [read, assign]

whether or not the texture has their Alpha premultiplied

- (GLfloat) maxS [read, write, assign]

texture max S

- (GLfloat) maxT [read, write, assign]

texture max T

- (GLuint) name [read, assign]

texture name

- (CCTexture2DPixelFormat) pixelFormat [read, assign]

pixel format of the texture

- (NSUInteger) pixelsHigh [read, assign]

hight in pixels

- (NSUInteger) pixelsWide [read, assign]

width in pixels

- (ccResolutionType) resolutionType [read, write, assign]

Returns the resolution type of the texture. Is it a RetinaDisplay texture, an iPad texture or an standard texture ? Only valid on iOS. Not valid on OS X.

Should be a readonly property. It is readwrite as a hack.

Since:
v1.1

The documentation for this class was generated from the following file: