KDvoid Controller::draw ( KDvoid )
{
    CC_NODE_DRAW_SETUP ( );
    
	GLfloat  fVertices [ ] = 
	{
		   0,  512, 
		1024,  512, 
		   0,    0, 
		1024,    0, 
	};

	GLfloat  fCoords [ ] =
	{
		   0,  0,
		   1,  0,
		   0,  1, 
		   1,  1, 
	};

	ccGLBindTexture2D ( m_uTexture );
    ccGLEnableVertexAttribs ( kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords );

	if ( m_pDrawFunc )
	{
		m_pDrawFunc ( KD_GET_UST2MSEC );
	}

	ccGLVertexAttribPointer ( kCCVertexAttrib_Position , 2, GL_FLOAT, GL_FALSE, 0, fVertices );
	ccGLVertexAttribPointer ( kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, fCoords );	

	glDrawArrays ( GL_TRIANGLE_STRIP, 0, 4 );

	ccGLBindTexture2D ( 0 );
}
Example #2
0
//-------------------------------------------------------------
//- Render
//- Renders a specific frame of the MD2 model
//-------------------------------------------------------------
void CCModelMd2::draw(unsigned int uiFrame)
{
    float* m_pUV = new float[m_Head.numTriangles * 6];
    memset(m_pUV, 0, m_Head.numTriangles * 6);

    float* m_pVertices = new float[m_Head.numTriangles * 9];
    memset(m_pVertices, 0, m_Head.numTriangles * 9);
    int uvIdx = 0;
    int vertexIdx = 0;
    for (int i =0; i < m_Head.numTriangles; i++)
    {
        m_pVertices[vertexIdx++] = m_pFrames[uiFrame].verts[m_pTriangles[i].vertIndices[0]].x;
        m_pVertices[vertexIdx++] = m_pFrames[uiFrame].verts[m_pTriangles[i].vertIndices[0]].y;
        m_pVertices[vertexIdx++] = m_pFrames[uiFrame].verts[m_pTriangles[i].vertIndices[0]].z;

        m_pVertices[vertexIdx++] = m_pFrames[uiFrame].verts[m_pTriangles[i].vertIndices[1]].x;
        m_pVertices[vertexIdx++] = m_pFrames[uiFrame].verts[m_pTriangles[i].vertIndices[1]].y;
        m_pVertices[vertexIdx++] = m_pFrames[uiFrame].verts[m_pTriangles[i].vertIndices[1]].z;

        m_pVertices[vertexIdx++] = m_pFrames[uiFrame].verts[m_pTriangles[i].vertIndices[2]].x;
        m_pVertices[vertexIdx++] = m_pFrames[uiFrame].verts[m_pTriangles[i].vertIndices[2]].y;
        m_pVertices[vertexIdx++] = m_pFrames[uiFrame].verts[m_pTriangles[i].vertIndices[2]].z;

        m_pUV[uvIdx++] = m_pTexCoords[m_pTriangles[i].texIndices[0]].s;
        m_pUV[uvIdx++] = m_pTexCoords[m_pTriangles[i].texIndices[0]].t;

        m_pUV[uvIdx++] = m_pTexCoords[m_pTriangles[i].texIndices[1]].s;
        m_pUV[uvIdx++] = m_pTexCoords[m_pTriangles[i].texIndices[1]].t;

        m_pUV[uvIdx++] = m_pTexCoords[m_pTriangles[i].texIndices[2]].s;
        m_pUV[uvIdx++] = m_pTexCoords[m_pTriangles[i].texIndices[2]].t;
    }

    ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords);

    if(!m_bIsCustomSkin) {
		if (m_pSkins) {
			ccGLBindTexture2D(m_pSkins[m_uiSkin].m_Image->getName());
		}
	} else {
        ccGLBindTexture2D(m_pCustSkin->getName());
	}

    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, m_pVertices);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, m_pUV);

    glDrawArrays(GL_TRIANGLES, 0, m_Head.numTriangles * 3);

    CC_INCREMENT_GL_DRAWS(1);
    CHECK_GL_ERROR_DEBUG();
    CC_SAFE_DELETE_ARRAY(m_pUV);
    CC_SAFE_DELETE_ARRAY(m_pVertices);
}
Example #3
0
/**
 * 绘制
 */
void MapCoordLine::draw(void)
{
	CC_PROFILER_START_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");

	CCAssert(!m_pobBatchNode, "If CCSprite is being rendered by CCSpriteBatchNode, CCSprite#draw SHOULD NOT be called");

	CC_NODE_DRAW_SETUP();

	ccGLBlendFunc( m_sBlendFunc.src, m_sBlendFunc.dst );

	if (m_pobTexture != NULL)
	{
		ccGLBindTexture2D( m_pobTexture->getName() );
	}
	else
	{
		ccGLBindTexture2D(0);
	}

	//
	// Attributes
	//

	ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex );

	#define kQuadSize sizeof(m_sQuad.bl)
	if (points.size())
	{
		long offset = (long)&points[0];

		// vertex
		int diff = offsetof( ccV3F_C4B_T2F, vertices);
		glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));

		// texCoods
		diff = offsetof( ccV3F_C4B_T2F, texCoords);
		glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));

		// color
		diff = offsetof( ccV3F_C4B_T2F, colors);
		glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));


		glDrawArrays(GL_LINES, 0, points.size());
	}
	CHECK_GL_ERROR_DEBUG();

	CC_INCREMENT_GL_DRAWS(1);

	CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
}
Example #4
0
void CCGSpell::onDraw(const Mat4 &transform, uint32_t flags)
{
	// 启用attributes变量输入,顶点坐标,纹理坐标,颜色
	ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);

	_pShaderProgram->use();
	_pShaderProgram->setUniformsForBuiltins(transform);

	// 绑定纹理到纹理槽0
	ccGLBindTexture2D(_texture->getName());
	long offset = (long)&_quad;

	// vertex
	int diff = offsetof(V3F_C4B_T2F, vertices);
	glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 3, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (void*)(offset + diff));

	// texCoods
	diff = offsetof(V3F_C4B_T2F, texCoords);
	glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_TEX_COORD, 2, GL_FLOAT, GL_FALSE, sizeof(V3F_C4B_T2F), (void*)(offset + diff));

	// color
	diff = offsetof(V3F_C4B_T2F, colors);
	glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_COLOR, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(V3F_C4B_T2F), (void*)(offset + diff));

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	CC_INCREMENT_GL_DRAWS(1);
}
Example #5
0
void GridBase::afterDraw(cocos2d::Node *target)
{
    _grabber->afterRender(_texture);

    // restore projection
    Director *director = Director::getInstance();
    director->setProjection(_directorProjection);

    if (target->getCamera()->isDirty())
    {
        Point offset = target->getAnchorPointInPoints();

        //
        // XXX: Camera should be applied in the AnchorPoint
        //
        kmGLTranslatef(offset.x, offset.y, 0);
        target->getCamera()->locate();
        kmGLTranslatef(-offset.x, -offset.y, 0);
    }

    ccGLBindTexture2D(_texture->getName());

    // restore projection for default FBO .fixed bug #543 #544
//TODO:         Director::getInstance()->setProjection(Director::getInstance()->getProjection());
//TODO:         Director::getInstance()->applyOrientation();
    blit();
}
Example #6
0
void TextureSprite::draw()
{
    if (!m_bVisible) return;

    CC_NODE_DRAW_SETUP();

    ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);

    ccGLBindTexture2D(mTexture2D->getName());
    ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords);

    /// Time offset
    getShaderProgram()->setUniformLocationWith2f(mTimeLocation, mTime.x, mTime.y);
    /// Color
    getShaderProgram()->setUniformLocationWith4f(mColorLocation, mColor.r, mColor.g, mColor.b, mColor.a);
    /// Vertex
    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, sizeof(ccVertex3F), (void*)&mVertexPos[0]);
    /// Texture coord.
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(ccTex2F), (void*)&mTexCoords[0]);
    /// Available mode: GL_TRIANGLES, GL_TRIANGLES_STRIP and GL_TRIANGLE_FAN
    glDrawArrays(GL_TRIANGLES, 0, mVertexPos.size());

    /// Do NOT call glFlush or performance will decrease drastically!
    /// glFlush();

    CHECK_GL_ERROR_DEBUG();

    CC_INCREMENT_GL_DRAWS(1);
}
void CCMotionStreak::draw()
{
    if(m_uNuPoints <= 1)
        return;

    CC_NODE_DRAW_SETUP(this);

    ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex );
    ccGLBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );

    ccGLBindTexture2D( m_pTexture->getName() );
    if(m_pTexture->isETC()) {
        getShaderProgram()->useSeparatedAlphaChannel(m_pTexture->getAlphaChannel()->getName());
    }
    
#ifdef EMSCRIPTEN
    // Size calculations from ::initWithFade
    setGLBufferData(m_pVertices, (sizeof(ccVertex2F) * m_uMaxPoints * 2), 0);
    glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, 0);

    setGLBufferData(m_pTexCoords, (sizeof(ccTex2F) * m_uMaxPoints * 2), 1);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, 0);

    setGLBufferData(m_pColorPointer, (sizeof(GLubyte) * m_uMaxPoints * 2 * 4), 2);
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, 0);
#else
    glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, m_pVertices);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, m_pTexCoords);
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, m_pColorPointer);
#endif // EMSCRIPTEN

    glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)m_uNuPoints*2);

    CC_INCREMENT_GL_DRAWS(1);
}
//--------------------------------------------------------
void CShaderNode::draw()
{
	CC_NODE_DRAW_SETUP();  

	//传递uniform变量  
	CCGLProgram* shader = getShaderProgram();  
	shader->setUniformLocationWith2f(m_unUniformResolution, m_tagResolutionPos.x, m_tagResolutionPos.y);
	shader->setUniformLocationWith1i(m_unUniformTex0, 0); 
	glUniform1f(m_unUniformTime, m_fTime);

	//获取attribute变量  
	CCSize size = this->getContentSize();  
	float w = size.width;  
	float h = size.height;  

	ccGLBindTexture2D(m_pTexture);								//绑定纹理到槽位  
	glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, w, h, 0); //截取屏幕数据到纹理  
	glEnableVertexAttribArray(m_unAttributePosition); 

	//传递attribute变量  
	GLfloat vertices[12] = {  
		0, 0, //左下0
		w, 0, //右下1
		w, h, //右上2
		0, 0, //左下0
		0, h, //左上3
		w, h, //右上2
	};  
	glVertexAttribPointer(m_unAttributePosition, 2, GL_FLOAT, GL_FALSE, 0, vertices);  
	glVertexAttrib4fv(m_unAttributeColor, m_fColor);  
	//绘制  
	glDrawArrays(GL_TRIANGLES, 0, 6);  
}
void CBTextureAtlas::drawNumberOfQuadsEx(unsigned int n, unsigned int start)
{    
    if (0 == n) 
    {
        return;
    }
    ccGLBindTexture2D(m_pTexture->getName());
	
	#define kQuadSize sizeof(m_pQuads[0].bl)
    ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);

    // vertices
	long offset = (long)m_pQuads;
	int diff = offsetof( ccV3F_C4B_T2F, vertices);
    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*)(offset + diff));

    // colors
	diff = offsetof(ccV3F_C4B_T2F, colors);
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*)(offset + diff));

    // tex coords
	diff = offsetof(ccV3F_C4B_T2F, texCoords);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*)(offset + diff));

#if CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP
    glDrawElements(GL_TRIANGLE_STRIP, (GLsizei)n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6 + m_pIndices));
#else
    glDrawElements(GL_TRIANGLES, (GLsizei)n*6, GL_UNSIGNED_SHORT, (GLvoid*) (start*6 + m_pIndices));
#endif // CC_TEXTURE_ATLAS_USE_TRIANGLE_STRIP

    CC_INCREMENT_GL_DRAWS(1);
    CHECK_GL_ERROR_DEBUG();
}
Example #10
0
bool CCTextureASTC::createGLTexture(){
    /* We now have file contents in memory so let's fill a texture object with the data. */
    if (m_uName != 0)
    {
        ccGLDeleteTexture(m_uName);
    }
    glGenTextures(1, &m_uName);
    ccGLBindTexture2D(m_uName);
    
    /* Upload texture data to ES. */
    glCompressedTexImage2D(GL_TEXTURE_2D,
                                    0,
                                    GL_COMPRESSED_RGBA_ASTC_6x5_KHR,
                                    m_uWidth,
                                    m_uHeight,
                                    0,
                                    m_dataLen,
                                    m_data+sizeof(astc_header));
    
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
    
    return true;
}
void BloodFlashSprite::draw()
{
    ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);
    ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    getShaderProgram()->use();
    getShaderProgram()->setUniformsForBuiltins();

    ccGLBindTexture2D(getTexture()->getName());

    // attributes.
#define kQuadSize sizeof(m_sQuad.bl)
    long offset = (long)&m_sQuad;

    //vertex
    int diff = offsetof(ccV3F_C4B_T2F, vertices);
    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));

    // texCoods.
    diff = offsetof(ccV3F_C4B_T2F, texCoords);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));

    // color
    diff = offsetof(ccV3F_C4B_T2F, colors);
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));

    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    CC_INCREMENT_GL_DRAWS(1);
}
Example #12
0
void BBWater::draw()
{
    CC_NODE_DRAW_SETUP();
    
//    ccGLBlendFunc( m_sBlendFunc.src, m_sBlendFunc.dst );
    
    ccGLBindTexture2D( m_sprite->getTexture()->getName() );
//    ccGLEnableVertexAttribs( kCCVertexAttribFlag_Position );
    
//    glBindBuffer(GL_ARRAY_BUFFER, m_vertexVbo);
//    glBufferData(GL_ARRAY_BUFFER, sizeof(float)*vertexArray.size(), &vertexArray[0], GL_STATIC_DRAW);
    
    glEnableVertexAttribArray( kCCVertexAttrib_Position );
    
    // vertex
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3, &vertexArray[0]);
    
//    // texCoods
//    diff = offsetof( ccV3F_C4B_T2F, texCoords);
//    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));
//    
//    // color
//    diff = offsetof( ccV3F_C4B_T2F, colors);
//    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));
    
    
    glDrawArrays(GL_TRIANGLES, 0, m_faceCount);
    
    CHECK_GL_ERROR_DEBUG();
}
void EXSunShineSprite::draw()
{
	ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);
    m_sBlendFunc.src = GL_DST_COLOR;
    m_sBlendFunc.dst = GL_ONE;
	ccGLBlendFunc( m_sBlendFunc.src, m_sBlendFunc.dst );
    
	this->getShaderProgram()->use();
	this->getShaderProgram()->setUniformsForBuiltins();
    
	ccGLBindTexture2D(  this->getTexture()->getName() );
    
#define kQuadSize sizeof(m_sQuad.bl)
	long offset = (long)&m_sQuad;
    
	// vertex
	int diff = offsetof( ccV3F_C4B_T2F, vertices);
	glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));
    
	// texCoods
	diff = offsetof( ccV3F_C4B_T2F, texCoords);
	glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));
    
	// color
	diff = offsetof( ccV3F_C4B_T2F, colors);
	glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	CC_INCREMENT_GL_DRAWS(1);
}
Example #14
0
void SpriteBlur::draw()
{
    ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex );
    ccGLBlendFunc( m_sBlendFunc.src, m_sBlendFunc.dst );

    getShaderProgram()->use();
    getShaderProgram()->setUniformForModelViewProjectionMatrix();
    getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y);
    getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1);

    ccGLBindTexture2D(  getTexture()->getName() );

    //
    // Attributes
    //
#define kQuadSize sizeof(m_sQuad.bl)
    long offset = (long)&m_sQuad;

    // vertex
    int diff = offsetof( ccV3F_C4B_T2F, vertices);
    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));

    // texCoods
    diff = offsetof( ccV3F_C4B_T2F, texCoords);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));

    // color
    diff = offsetof( ccV3F_C4B_T2F, colors);
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));


    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    CC_INCREMENT_GL_DRAWS(1);
}
Example #15
0
void RigidBlock::draw()
{   
	if(!m_isAlive)
		return;

    ccGLBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    m_vertexCoord[0] = Vertex2DMake((m_position.x - m_size.width/2), (m_position.y + m_size.height/2) );
    m_vertexCoord[1] = Vertex2DMake((m_position.x + m_size.width/2), (m_position.y + m_size.height/2));
    m_vertexCoord[2] = Vertex2DMake((m_position.x - m_size.width/2), (m_position.y - m_size.height/2) );
    m_vertexCoord[3] = Vertex2DMake((m_position.x + m_size.width/2), (m_position.y - m_size.height/2));


 /*   m_vertexCoord[0] = Vertex2DMake( -m_size.width/2, m_size.height/2);
    m_vertexCoord[1] = Vertex2DMake( m_size.width/2, m_size.height/2);
    m_vertexCoord[2] = Vertex2DMake( -m_size.width/2, -m_size.height/2);
    m_vertexCoord[3] = Vertex2DMake( m_size.width/2, -m_size.height/2);*/

	ccGLBindTexture2D(m_texture->getName());
	m_texture->getShaderProgram()->use();
	m_texture->getShaderProgram()->setUniformsForBuiltins();
	ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords);
	glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, m_textCoord);
	glVertexAttribPointer(kCCVertexAttrib_Position,  2, GL_FLOAT, GL_FALSE, 0, m_vertexCoord);

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
}
Example #16
0
void CCGridBase::afterDraw(cocos2d::CCNode *pTarget)
{
    m_pGrabber->afterRender(m_pTexture);

    // restore projection
    CCDirector *director = CCDirector::sharedDirector();
    director->setProjection(m_directorProjection);

    if (pTarget->getCamera()->isDirty())
    {
        CCPoint offset = pTarget->getAnchorPointInPoints();

        //
        // XXX: Camera should be applied in the AnchorPoint
        //
        kmGLTranslatef(offset.x, offset.y, 0);
        pTarget->getCamera()->locate();
        kmGLTranslatef(-offset.x, -offset.y, 0);
    }

    ccGLBindTexture2D(m_pTexture->getName());

    // restore projection for default FBO .fixed bug #543 #544
//TODO:         CCDirector::sharedDirector()->setProjection(CCDirector::sharedDirector()->getProjection());
//TODO:         CCDirector::sharedDirector()->applyOrientation();
    blit();
}
//--------------------------------------------------------
void CRemoveBKSprite::draw(void)
{
	CC_PROFILER_START_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
	CCAssert(!m_pobBatchNode, "If CCSprite is being rendered by CCSpriteBatchNode, CCSprite#draw SHOULD NOT be called");

	CC_NODE_DRAW_SETUP();

	// 启用attributes变量输入,顶点坐标,纹理坐标,颜色
	ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex );
	ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);

	m_pShaderProgram->use();
	m_pShaderProgram->setUniformsForBuiltins();

	// 绑定纹理到纹理槽0
	ccGLBindTexture2D(m_pobTexture->getName());

	long offset = (long)&m_sQuad;
	// vertex
	int diff = offsetof( ccV3F_C4B_T2F, vertices);
	glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, sizeof(m_sQuad.bl), (void*) (offset + diff));
	// texCoods
	diff = offsetof( ccV3F_C4B_T2F, texCoords);
	glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(m_sQuad.bl), (void*)(offset + diff));
	// color
	diff = offsetof( ccV3F_C4B_T2F, colors);
	glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(m_sQuad.bl), (void*)(offset + diff));

	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	CHECK_GL_ERROR_DEBUG();

	CC_INCREMENT_GL_DRAWS(1);
	CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
}
Example #18
0
void FXLightning::render(){

	float angle = atan2f(end.y - start.y , end.x - start.x);
	float x = cosf(angle - M_PI/2.0) * width;
	float y = sinf(angle - M_PI/2.0) * width;
	float rx = cosf(angle - M_PI/2.0) * spread;
	float ry = sinf(angle - M_PI/2.0) * spread;
    static int counter = 0;
	
	int n_samples = ccpDistance(start, end)/480 * K_NUMBER_OF_LIGHTNING_SAMPLES;
	if (n_samples > K_NUMBER_OF_LIGHTNING_SAMPLES) {
		n_samples = K_NUMBER_OF_LIGHTNING_SAMPLES;
	}
   
	for (int i=0; i < n_samples; i+=2) {
        CCPoint p = ccpLerp(start, end, i/(float)(n_samples-1));
		float r = ((rand()%100) / 100.0 - 0.5) * 7;
//        float r = 20* noise1(counter*speed);
        float w = 0;
        if (i < n_samples*0.5) {
            w = i/(float)n_samples * 3;
        }
        else{
            w = (n_samples-i-2)/(float)n_samples * 3;
        }
        w = clampf(w, 0, 1);
        if (tapper == 0) {
            vtx[ i+0 ].x = p.x + x + rx*r*w;
            vtx[ i+0 ].y = p.y + y + ry*r*w;
            
            vtx[ i+1 ].x = p.x - x + rx*r*w;
            vtx[ i+1 ].y = p.y - y + ry*r*w;
        }
        else{
            vtx[ i+0 ].x = p.x + x*tapper*(1-i/(float)n_samples) + rx*r;
            vtx[ i+0 ].y = p.y + y*tapper*(1-i/(float)n_samples) + ry*r;
            
            vtx[ i+1 ].x = p.x - x*tapper*(1-i/(float)n_samples) + rx*r;
            vtx[ i+1 ].y = p.y - y*tapper*(1-i/(float)n_samples) + ry*r;
        }
        counter+=5;
	}
    
    
    
    pShaderProgram->use();
    pShaderProgram->setUniformsForBuiltins();
    
    ccGLBindTexture2D(texture->getName());
    
    glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, vtx);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, uvs);
    glDrawArrays(GL_TRIANGLE_STRIP, 0,n_samples);
    
    //DEBUG
//    glDrawArrays(GL_LINE_STRIP, 0, n_samples);
    
    CC_INCREMENT_GL_DRAWS(1);
}
Example #19
0
void HueSprite::draw()
{

    CC_PROFILER_START_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
        
	CCAssert(!m_pobBatchNode, "If CCSprite is being rendered by CCSpriteBatchNode, CCSprite#draw SHOULD NOT be called");
        
	//CC_NODE_DRAW_SETUP();
	ccGLEnable( m_eGLServerState );
        
	ccGLBlendFunc( m_sBlendFunc.src, m_sBlendFunc.dst );
        
	m_shader->use();
    m_shader->setUniformsForBuiltins();


	if (m_pobTexture != NULL)
	{
		//ccGLBindTexture2D( m_texure1->getName());
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, m_pobTexture->getName());
	}
	else
	{
		ccGLBindTexture2D(0);
	}


	glUniformMatrix3fv(m_loc_hue, 1, GL_FALSE, (GLfloat*)&m_mat);

	//
	// Attributes
	//
	ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex );
        
#define kQuadSize sizeof(m_sQuad.bl)
	long offset = (long)&m_sQuad;
        
	// vertex
	int diff = offsetof( ccV3F_C4B_T2F, vertices);
	glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));
        
	// texCoods
	diff = offsetof( ccV3F_C4B_T2F, texCoords);
	glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));
        
	// color
	diff = offsetof( ccV3F_C4B_T2F, colors);
	glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));
        
        
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
        
	CHECK_GL_ERROR_DEBUG();
        
	CC_INCREMENT_GL_DRAWS(1);
        
	CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
}
// overriding draw method
void CCParticleSystemQuad::draw()
{    
    CCAssert(!m_pBatchNode,"draw should not be called when added to a particleBatchNode");

    CC_NODE_DRAW_SETUP();

    ccGLBindTexture2D( m_pTexture->getName() );
    ccGLBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );

    CCAssert( m_uParticleIdx == m_uParticleCount, "Abnormal error in particle quad");

#if CC_TEXTURE_ATLAS_USE_VAO
    //
    // Using VBO and VAO
    //
    glBindVertexArray( m_uVAOname );

#if CC_REBIND_INDICES_BUFFER
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);
#endif

    glDrawElements(GL_TRIANGLES, (GLsizei) m_uParticleIdx*6, GL_UNSIGNED_SHORT, 0);

#if CC_REBIND_INDICES_BUFFER
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
#endif

    glBindVertexArray( 0 );

#else
    //
    // Using VBO without VAO
    //

    #define kQuadSize sizeof(m_pQuads[0].bl)

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex );

    glBindBuffer(GL_ARRAY_BUFFER, m_pBuffersVBO[0]);
    // vertices
    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, vertices));
    // colors
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, colors));
    // tex coords
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (GLvoid*) offsetof( ccV3F_C4B_T2F, texCoords));
    
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_pBuffersVBO[1]);

    glDrawElements(GL_TRIANGLES, (GLsizei) m_uParticleIdx*6, GL_UNSIGNED_SHORT, 0);

    glBindBuffer(GL_ARRAY_BUFFER, 0);
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);

#endif

    CC_INCREMENT_GL_DRAWS(1);
    CHECK_GL_ERROR_DEBUG();
}
void CtinyWingsTerrainSprite::draw(){
    
    //----change shader
    ccGLBlendFunc( m_sBlendFunc.src, m_sBlendFunc.dst );
    ccGLEnable(m_eGLServerState);
    //pass values for cocos2d-x build-in uniforms
    this->setShaderProgram(m_program);
    CGLProgramWithUnifos*program=(CGLProgramWithUnifos*)this->getShaderProgram();
    program->use();
    program->setUniformsForBuiltins();
    //pass values for my own uniforms
    float colorList_tmp[4*3]={m_colorList[0].r,m_colorList[0].g,m_colorList[0].b,m_colorList[0].a,
        m_colorList[1].r,m_colorList[1].g,m_colorList[1].b,m_colorList[1].a,
        m_colorList[2].r,m_colorList[2].g,m_colorList[2].b,m_colorList[2].a};
    program->passUnifoValue1f("u_texNonlinearFactor", m_texNonlinearFactor);
    program->passUnifoValueNfvN("u_colors", colorList_tmp, 4, 3);
    program->passUnifoValue1f("u_cosA", cosf(m_ribbonRotation*M_PI/180));
    program->passUnifoValue1f("u_sinA", sinf(m_ribbonRotation*M_PI/180));
    program->passUnifoValue1f("u_ribbonRepeat", m_ribbonRepeat);
    //enable attributes
    bool isAttribPositionOn=CindexVBO::isEnabledAttribArray_position();
    bool isAttribColorOn=CindexVBO::isEnabledAttribArray_color();
    bool isAttribTexCoordOn=CindexVBO::isEnabledAttribArray_texCoord();
    CindexVBO::enableAttribArray_position(true);
    CindexVBO::enableAttribArray_color(true);
    CindexVBO::enableAttribArray_texCoord(true);
    //bind texture
    ccGLBindTexture2D( this->getTexture()->getName());
    //draw m_indexVBO
    m_indexVBO->setPointer_position();
    m_indexVBO->setPointer_texCoord();
    m_indexVBO->setPointer_color();
    m_indexVBO->draw(GL_TRIANGLES);
    //unbind texture
    ccGLBindTexture2D(0);
    //disable attributes
    CindexVBO::enableAttribArray_position(isAttribPositionOn);
    CindexVBO::enableAttribArray_color(isAttribColorOn);
    CindexVBO::enableAttribArray_texCoord(isAttribTexCoordOn);
    //draw wire
    if(m_isDrawDebug){
        drawWire();
    }
}
Example #22
0
void CCSprite3D::draw()
{
//    m_bDepthTestEnabled = 0 == glIsEnabled(GL_DEPTH_TEST) ? false : true;
//
//    CCDirector::sharedDirector()->setDepthTest(true);
//
    CC_NODE_DRAW_SETUP();

//    getShaderProgram()->use();
//    getShaderProgram()->setUniformsForBuiltins();

    CCPoint const & origin = ccp(0, 0);
    CCPoint const & destination = ccp(100, 100);

    ccVertex3F vertices[3] = {
//        {origin.x, origin.y, 100},
            {destination.x, origin.y, 200},
            {destination.x, destination.y, 100},
            {origin.x, destination.y, 200}
    };

    ccTex2F uv[3] = {
//        {0.0f, 0.0f},
            {1.0f, 0.0f},
            {1.0f, 1.0f},
            {0.0f, 1.0f}
    };

    ccColor4B colors[3] = {
//        {255, 255, 255, 255},
            {128, 128, 128, 128},
            {128, 128, 128, 128},
            {255, 255, 255, 255}
    };

    ccGLBindTexture2D(mCustSkin->getName());

    ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex );
    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, 0, vertices);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, uv);
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, colors);
    glDrawArrays(GL_TRIANGLES, 0, 3);

    CHECK_GL_ERROR_DEBUG();

    CC_INCREMENT_GL_DRAWS(1);

//    m_pModel->draw();
//    static unsigned int uiStartFrame = 0, uiEndFrame = 182;
//    static float fAnimSpeed = 16.5f;
//   ((CCModelMd2*)m_pModel)->animate(fAnimSpeed, uiStartFrame, uiEndFrame, true);
//   CCDirector::sharedDirector()->setDepthTest(m_bDepthTestEnabled);
}
	void Cocos2dRenderManager::doRender(IVertexBuffer* _buffer, ITexture* _texture, size_t _count)
	{
		Cocos2dVertexBuffer* buffer = static_cast<Cocos2dVertexBuffer*>(_buffer);
		unsigned int buffer_id = buffer->getBufferID();

		unsigned int texture_id = 0;
		Cocos2dTexture* texture = static_cast<Cocos2dTexture*>(_texture);
		texture_id = texture->getGLTexture();

		//MYGUI_PLATFORM_ASSERT(buffer_id, "Texture is not created");
		//MYGUI_PLATFORM_ASSERT(texture_id, "Texture is not created");
		if (!buffer_id) return;
		if (!texture_id) return;

		ccGLEnable(m_eGLServerState);

		CCGLProgram* shaderProgram = NULL;
		cocos2d::ccBlendFunc blendFunc;

		shaderProgram = CCShaderCache::sharedShaderCache()->programForKey(kCCShader_PositionTextureColor_MyGUI);
		// 对于
		if (texture->getCocos2dTexture()->hasPremultipliedAlpha())
		{
			blendFunc.src = CC_BLEND_SRC;
			blendFunc.dst = CC_BLEND_DST;
		}
		else
		{
			blendFunc.src = GL_SRC_ALPHA;
			blendFunc.dst = GL_ONE_MINUS_SRC_ALPHA;
		}

		shaderProgram->use();
		shaderProgram->setUniformsForBuiltins();
		ccGLBlendFunc(blendFunc.src, blendFunc.dst);

		ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex );

		ccGLBindTexture2D(texture_id);
		glBindBuffer(GL_ARRAY_BUFFER, buffer_id);

		glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, x));
		glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(Vertex), (void*)offsetof(Vertex, colour));
		glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, u));

		glDrawArrays(GL_TRIANGLES, 0, _count);

		vbo_count++;
		vertex_count += _count;

		glBindBuffer(GL_ARRAY_BUFFER, 0);
	}
Example #24
0
void Forest::draw() {
	CCNode::draw();

	CC_NODE_DRAW_SETUP();

	ccGLBindTexture2D(_forestTexture->getName());
	ccGLEnableVertexAttribs(
			kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords);

	ccDrawColor4F(1.0f, 1.0f, 1.0f, 1.0f);
	glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0,
			_forestVertices);
	glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0,
			_forestTexCoords);
	glDrawArrays(GL_TRIANGLES, 0, (GLsizei) _nForestVertices);
}
void ShaderSprite::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags)
{
    CC_PROFILER_START_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");

    // CCAssert(, "If CCSprite is being rendered by CCSpriteBatchNode, CCSprite#draw SHOULD NOT be called");

    CC_NODE_DRAW_SETUP();

    //
    // 启用attributes变量输入,顶点坐标,纹理坐标,颜色
    //
    ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex );
    ccGLBlendFunc(this->getBlendFunc().src, this->getBlendFunc().dst);

    this->getShaderProgram()->use();
    this->getShaderProgram()->setUniformsForBuiltins();

    // 绑定纹理到纹理槽0
    ccGLBindTexture2D(this->getTexture()->getName());



#define kQuadSize sizeof(this->_quad.bl)
    long offset = (long)&this->_quad;

    // vertex
    int diff = offsetof( ccV3F_C4B_T2F, vertices);
    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, kQuadSize, (void*) (offset + diff));

    // texCoods
    diff = offsetof( ccV3F_C4B_T2F, texCoords);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));

    // color
    diff = offsetof( ccV3F_C4B_T2F, colors);
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, kQuadSize, (void*)(offset + diff));


    glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

    CHECK_GL_ERROR_DEBUG();

    CC_INCREMENT_GL_DRAWS(1);
    CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");
}
Example #26
0
void CCMotionStreak::draw()
{
    if(m_uNuPoints <= 1)
        return;

    CC_NODE_DRAW_SETUP();

    ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex );
    ccGLBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );

    ccGLBindTexture2D( m_pTexture->getName() );

    glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, m_pVertices);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, m_pTexCoords);
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, 0, m_pColorPointer);

    glDrawArrays(GL_TRIANGLE_STRIP, 0, (GLsizei)m_uNuPoints*2);

    CC_INCREMENT_GL_DRAWS(1);
}
Example #27
0
void CCBlade::draw()
{
    if (_path.size() < POINT_LIMIT_MIN) {
        return;
    }
    
    CC_NODE_DRAW_SETUP();
    ccGLEnableVertexAttribs(kCCVertexAttribFlag_Position | kCCVertexAttribFlag_TexCoords);
    
    const ccColor3B &realColor = getColor();
    GLfloat color[4] = { realColor.r/255.0f, realColor.g/255.0f, realColor.b/255.0f, getOpacity()/255.0f };
    getShaderProgram()->setUniformLocationWith4fv(_uniformColor, color, 1);
    ccGLBindTexture2D(_texture->getName());
    
    glVertexAttribPointer(kCCVertexAttrib_Position, 2, GL_FLOAT, GL_FALSE, 0, _vertices);
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, 0, _texCoords);
    glDrawArrays(GL_TRIANGLE_STRIP, 0, 2*_path.size()-2);
    
    CC_INCREMENT_GL_DRAWS(1);
}
void SpriteBlur::initProgram()
{
	GLchar * fragSource = (GLchar*) CCString::createWithContentsOfFile(
		CCFileUtils::sharedFileUtils()->fullPathForFilename("Shaders/example_Blur.fsh").c_str())->getCString();
	CCGLProgram* pProgram = new CCGLProgram();
	pProgram->initWithVertexShaderByteArray(ccPositionTextureColor_vert, fragSource);
	setShaderProgram(pProgram);
	pProgram->release();

	CHECK_GL_ERROR_DEBUG();

	getShaderProgram()->addAttribute(kCCAttributeNamePosition, kCCVertexAttrib_Position);
	getShaderProgram()->addAttribute(kCCAttributeNameColor, kCCVertexAttrib_Color);
	getShaderProgram()->addAttribute(kCCAttributeNameTexCoord, kCCVertexAttrib_TexCoords);

	CHECK_GL_ERROR_DEBUG();

	getShaderProgram()->link();

	CHECK_GL_ERROR_DEBUG();

	getShaderProgram()->updateUniforms();

	CHECK_GL_ERROR_DEBUG();

	subLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "substract");
	blurLocation = glGetUniformLocation( getShaderProgram()->getProgram(), "blurSize");

	CHECK_GL_ERROR_DEBUG();
    
    ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex );
	ccBlendFunc blend = getBlendFunc();
	ccGLBlendFunc(blend.src, blend.dst);
    
	getShaderProgram()->use();
	getShaderProgram()->setUniformsForBuiltins();
	getShaderProgram()->setUniformLocationWith2f(blurLocation, blur_.x, blur_.y);
	getShaderProgram()->setUniformLocationWith4fv(subLocation, sub_, 1);
    
	ccGLBindTexture2D( getTexture()->getName());    
}
Example #29
0
void Live2dXUnit::draw()
{
    if (m_texture == 0)
    {
        return;
    }
#define Live2dX_Vertex_Size sizeof(Live2dX_Vertex)
#define Live2dX_UV_Size sizeof(Live2dX_UV)
#define Live2dX_Color_Size sizeof(Live2dX_Color)
   
    ccGLBindTexture2D( m_texture->getName() );

    ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex );
    
    // vertex
    glVertexAttribPointer(kCCVertexAttrib_Position, 3, GL_FLOAT, GL_FALSE, Live2dX_Vertex_Size, (void*)m_now_vertex.data());
    glVertexAttribPointer(kCCVertexAttrib_TexCoords, 2, GL_FLOAT, GL_FALSE, Live2dX_UV_Size, (void*)m_all_uv.data());
    glVertexAttribPointer(kCCVertexAttrib_Color, 4, GL_UNSIGNED_BYTE, GL_TRUE, Live2dX_Color_Size, (void*)m_now_color.data());
    
    glDrawElements(GL_TRIANGLES,(GLsizei)m_all_triangle.size()*3, GL_UNSIGNED_SHORT, m_all_triangle.data());
}
KDvoid Controller::setExample ( KDint nIndex )
{
	KDubyte*  pPixels = (KDubyte*) kdCalloc ( 1024 * 512 * 3, 1 );

	ccGLBindTexture2D ( m_uTexture );
	glTexImage2D  ( GL_TEXTURE_2D, 0, GL_RGB, 1024, 512, 0, GL_RGB, GL_UNSIGNED_BYTE, pPixels );

	kdFree ( pPixels );

	if ( m_pExitFunc )
	{
		m_pExitFunc ( );
	}

	m_nIndex    = nIndex;
	m_pDrawFunc = KD_NULL;
	m_pExitFunc = KD_NULL;

	m_pTitle->setString ( l_aExamples [ nIndex ].title );
	m_pSubTitle->setString ( l_aExamples [ nIndex ].subtitle );
	m_pMessage->setString ( "" );

	l_aExamples [ nIndex ].func ( l_aExamples [ nIndex ].index );
}