Class CCTexture2D

#include <Geode/cocos/textures/CCTexture2D.h>
classCCTexture2D:publiccocos2d::CCObject{ ... }

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!

Examples0
Public static methods3
staticvoidsetDefaultAlphaPixelFormat()

Since v0.8

sets the default pixel format for UIImagescontains alpha channel. If the UIImage contains alpha channel, then the options are:

  • generate 32-bit textures: kCCTexture2DPixelFormat_RGBA8888 (default one)
  • generate 24-bit textures: kCCTexture2DPixelFormat_RGB888
  • 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: 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.
staticcocos2d::CCTexture2DPixelFormatdefaultAlphaPixelFormat()

Since v0.8

returns the alpha pixel format

staticvoidPVRImagesHavePremultipliedAlpha(
boolhaveAlphaPremultiplied
)

Since v0.99.5

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.

Public member functions34
charconst*description()
No description provided
voidreleaseData(
void*data
)

These functions are needed to create mutable textures

void*keepData(
void*data
,
uintlength
)
No description provided
boolinitWithData(,,
uintpixelsWide
,
uintpixelsHigh
,)

Initializes with a texture2d with data

voiddrawAtPoint()

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. / /** draws a texture at a given point

voiddrawInRect()

draws a texture inside a rect

boolinitWithImage()

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). / /** Initializes a texture from a UIImage object

boolinitWithString(,
charconst*fontName
,
floatfontSize
,,,)

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

boolinitWithString(,
charconst*fontName
,
floatfontSize
)

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

boolinitWithString(,)

Initializes a texture from a string using a text definition

boolinitWithPVRFile()

Initializes a texture from a PVR file

boolinitWithETCFile()

Initializes a texture from a ETC file

voidsetTexParameters()

Since v0.8

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

⚠️ Calling this method could allocate additional texture memory.

when this functon bound to js,the input param are changed
js: var setTexParameters(var minFilter, var magFilter, var wrapS, var wrapT)
voidsetAntiAliasTexParameters()

Since v0.8

sets antialias texture parameters:

  • GL_TEXTURE_MIN_FILTER = GL_LINEAR
  • GL_TEXTURE_MAG_FILTER = GL_LINEAR

⚠️ Calling this method could allocate additional texture memory.

voidsetAliasTexParameters()

Since v0.8

sets alias texture parameters:

  • GL_TEXTURE_MIN_FILTER = GL_NEAREST
  • GL_TEXTURE_MAG_FILTER = GL_NEAREST

⚠️ Calling this method could allocate additional texture memory.

voidgenerateMipmap()

Since v0.99.0

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

charconst*stringForFormat()

Since v2.0

returns the pixel format.

uintbitsPerPixelForFormat()

Since v1.0

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

uintbitsPerPixelForFormat()

Since v2.0

Helper functions that returns bits per pixels for a given format.

cocos2d::CCSizeconst&getContentSizeInPixels()

content size

boolhasPremultipliedAlpha()
No description provided
boolhasMipmaps()
No description provided
voidreleaseGLTexture()
No description provided
virtualcocos2d::CCTexture2DPixelFormatgetPixelFormat()

pixel format of the texture

virtualuintgetPixelsWide()

width in pixels

virtualuintgetPixelsHigh()

height in pixels

virtual_::GLuintgetName()

texture name

virtual_::GLfloatgetMaxS()

texture max S

virtualvoidsetMaxS()

texture max S

virtual_::GLfloatgetMaxT()

texture max T

virtualvoidsetMaxT()

texture max T

virtualcocos2d::CCSizegetContentSize()

content size

virtualcocos2d::CCGLProgram*getShaderProgram()

shader program used by drawAtPoint and drawInRect

virtualvoidsetShaderProgram()

shader program used by drawAtPoint and drawInRect

Fields2
boolm_bHasPremultipliedAlpha
;

whether or not the texture has their Alpha premultiplied

boolm_bHasMipmaps
;
No description provided
Protected member functions0
Protected fields8
;

pixel format of the texture

uintm_uPixelsWide
;

width in pixels

uintm_uPixelsHigh
;

height in pixels

_::GLuintm_uName
;

texture name

_::GLfloatm_fMaxS
;

texture max S

_::GLfloatm_fMaxT
;

texture max T

cocos2d::CCSizem_tContentSize
;

content size

cocos2d::CCGLProgram*m_pShaderProgram
;

shader program used by drawAtPoint and drawInRect