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!
Class CCTexture2D
#include <Geode/cocos/textures/CCTexture2D.h>
Examples0
Public static methods3
staticvoidsetDefaultAlphaPixelFormat()
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()
returns the alpha pixel format
staticvoidPVRImagesHavePremultipliedAlpha(boolhaveAlphaPremultiplied)
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()
boolinitWithData(voidconst*data,cocos2d::CCTexture2DPixelFormatpixelFormat,uintpixelsWide,uintpixelsHigh,cocos2d::CCSizeconst&contentSize)
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(cocos2d::CCImage*uiImage)
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*text,charconst*fontName,floatfontSize,cocos2d::CCSizeconst&dimensions,cocos2d::CCTextAlignmenthAlignment,cocos2d::CCVerticalTextAlignmentvAlignment)
Initializes a texture from a string with dimensions, alignment, font name and font size
boolinitWithString(charconst*text,charconst*fontName,floatfontSize)
Initializes a texture from a string with font name and font size
boolinitWithString(charconst*text,cocos2d::ccFontDefinition*textDefinition)
Initializes a texture from a string using a text definition
boolinitWithPVRFile(charconst*file)
Initializes a texture from a PVR file
boolinitWithETCFile(charconst*file)
Initializes a texture from a ETC file
voidsetTexParameters(cocos2d::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}.
⚠️ 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()
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()
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()
Generates mipmap images for the texture. It only works if the texture size is POT (power of 2).
charconst*stringForFormat()
returns the pixel format.
uintbitsPerPixelForFormat()
returns the bits-per-pixel of the in-memory OpenGL texture
uintbitsPerPixelForFormat()
Helper functions that returns bits per pixels for a given format.
cocos2d::CCSizeconst&getContentSizeInPixels()
content size
boolhasPremultipliedAlpha()
boolhasMipmaps()
voidreleaseGLTexture()
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(_::GLfloatvar)
texture max S
virtual_::GLfloatgetMaxT()
texture max T
virtualvoidsetMaxT(_::GLfloatvar)
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
Protected member functions0
Protected fields8
cocos2d::CCTexture2DPixelFormatm_ePixelFormat;
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