Ejemplo n.º 1
0
	void CCLabelAtlas::draw()
	{
		CCAtlasNode::draw();

		const CCSize& s = this->getContentSize();
		CCPoint vertices[4]={
			ccp(0,0),ccp(s.width,0),
			ccp(s.width,s.height),ccp(0,s.height),
		};
		ccDrawPoly(vertices, 4, true);
	}
Ejemplo n.º 2
0
void CCSprite::draw(void)
{
	assert(! m_bUsesBatchNode);

	// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
	// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
	// Unneeded states: -
	bool newBlend = m_sBlendFunc.src != CC_BLEND_SRC || m_sBlendFunc.dst != CC_BLEND_DST;
	if (newBlend)
	{
		glBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
	}

#define kQuadSize sizeof(m_sQuad.bl)
    if (m_pobTexture)
    {
        glBindTexture(GL_TEXTURE_2D, m_pobTexture->getName());
    }
    else
    {
        glBindTexture(GL_TEXTURE_2D, 0);
    }

	long offset = (long)&m_sQuad;

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

	// color
	diff = offsetof( ccV3F_C4B_T2F, colors);
	glColorPointer(4, GL_UNSIGNED_BYTE, kQuadSize, (void*)(offset + diff));
	
	// tex coords
	diff = offsetof( ccV3F_C4B_T2F, texCoords);
	glTexCoordPointer(2, GL_FLOAT, kQuadSize, (void*)(offset + diff));
	
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	
	if( newBlend )
	{
		glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);
	}

#if CC_SPRITE_DEBUG_DRAW
	CGSize s = m_tContentSize;
	CGPoint vertices[4]={
		ccp(0,0),ccp(s.width,0),
		ccp(s.width,s.height),ccp(0,s.height),
	};
	ccDrawPoly(vertices, 4, true);
#endif // CC_SPRITE_DEBUG_DRAW
}
Ejemplo n.º 3
0
void CCSkeleton::draw () {
	CC_NODE_DRAW_SETUP();

	ccGLBlendFunc(blendFunc.src, blendFunc.dst);
	ccColor3B color = getColor();
	skeleton->r = color.r / (float)255;
	skeleton->g = color.g / (float)255;
	skeleton->b = color.b / (float)255;
	skeleton->a = getOpacity() / (float)255;

	quadCount = 0;
	for (int i = 0, n = skeleton->slotCount; i < n; i++)
		if (skeleton->slots[i]->attachment) Attachment_draw(skeleton->slots[i]->attachment, skeleton->slots[i]);
	if (atlas) atlas->drawNumberOfQuads(quadCount);

	if (debugSlots) {
		// Slots.
		ccDrawColor4B(0, 0, 255, 255);
		glLineWidth(1);
		CCPoint points[4];
		for (int i = 0, n = skeleton->slotCount; i < n; i++) {
			if (!skeleton->slots[i]->attachment) continue;
			ccV3F_C4B_T2F_Quad* quad = &((Cocos2dxRegionAttachment*)skeleton->slots[i]->attachment)->quad;
			points[0] = ccp(quad->bl.vertices.x, quad->bl.vertices.y);
			points[1] = ccp(quad->br.vertices.x, quad->br.vertices.y);
			points[2] = ccp(quad->tr.vertices.x, quad->tr.vertices.y);
			points[3] = ccp(quad->tl.vertices.x, quad->tl.vertices.y);
			ccDrawPoly(points, 4, true);
		}
	}
	if (debugBones) {
		// Bone lengths.
		glLineWidth(2);
		ccDrawColor4B(255, 0, 0, 255);
		for (int i = 0, n = skeleton->boneCount; i < n; i++) {
			Bone *bone = skeleton->bones[i];
			float x = bone->data->length * bone->m00 + bone->worldX;
			float y = bone->data->length * bone->m10 + bone->worldY;
			ccDrawLine(ccp(bone->worldX, bone->worldY), ccp(x, y));
		}
		// Bone origins.
		ccPointSize(4);
		ccDrawColor4B(0, 0, 255, 255); // Root bone is blue.
		for (int i = 0, n = skeleton->boneCount; i < n; i++) {
			Bone *bone = skeleton->bones[i];
			ccDrawPoint(ccp(bone->worldX, bone->worldY));
			if (i == 0) ccDrawColor4B(0, 255, 0, 255);
		}
	}
}
Ejemplo n.º 4
0
void CGameTableViewCell::draw()
{
	CCTableViewCell::draw();
	// draw bounding box
 	CCPoint pos = getPosition();
	CCSize size = CCSizeMake(GAME_ICON_WIDTH, GAME_ICON_HEIGHT);
 	CCPoint vertices[4]={
 		ccp(pos.x+1, pos.y+1),
 		ccp(pos.x+size.width-1, pos.y+1),
 		ccp(pos.x+size.width-1, pos.y+size.height-1),
 		ccp(pos.x+1, pos.y+size.height-1),
 	};
 	ccDrawColor4B(0, 0, 255, 255);
 	ccDrawPoly(vertices, 4, true);
}
Ejemplo n.º 5
0
void LabelBMFontBounds::draw()
{
    CCSize labelSize = label1->getContentSize();
    CCSize origin = CCDirector::sharedDirector()->getWinSize();
    
    origin.width = origin.width / 2 - (labelSize.width / 2);
    origin.height = origin.height / 2 - (labelSize.height / 2);
    
    CCPoint vertices[4]=
    {
        ccp(origin.width, origin.height),
        ccp(labelSize.width + origin.width, origin.height),
        ccp(labelSize.width + origin.width, labelSize.height + origin.height),
        ccp(origin.width, labelSize.height + origin.height)
    };
    ccDrawPoly(vertices, 4, true);
}
Ejemplo n.º 6
0
void CCPolygonShape::drawProc(void)
{
    const CCPoint center = getDrawPosition();
    for (unsigned int i = 0; i < m_numberOfVertices; ++i)
    {
        m_verticesDraw[i].x = m_vertices[i].x + center.x;
        m_verticesDraw[i].y = m_vertices[i].y + center.y;
    }
    
    if (m_fill)
    {
        ccDrawSolidPoly(m_verticesDraw, m_numberOfVertices, m_color);
    }
    else
    {
        ccDrawColor4F(m_color.r, m_color.g, m_color.b, m_color.a);
        ccDrawPoly(m_verticesDraw, m_numberOfVertices, m_close);
    }
}
Ejemplo n.º 7
0
void CCRichAtlas::draw()
{
	if ( m_dirty )
	{
		this->updateRichRenderData();
	}

	CCAtlasNode::draw();

#if CCRICH_DEBUG
	// atlas bounding box
	const CCSize& s = this->getContentSize();
	CCPoint vertices[4]={
		ccp(0,0),ccp(s.width,0),
		ccp(s.width,s.height),ccp(0,s.height),
	};
	ccDrawColor4B(0x00, 0xff, 0x00, 0xff);
	ccDrawPoly(vertices, 4, true);
#endif
}
Ejemplo n.º 8
0
	// XXX: overriding draw from AtlasNode
	void CCLabelAtlas::draw()
	{
		// Default GL states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_COLOR_ARRAY, GL_TEXTURE_COORD_ARRAY
		// Needed states: GL_TEXTURE_2D, GL_VERTEX_ARRAY, GL_TEXTURE_COORD_ARRAY
		// Unneeded states: GL_COLOR_ARRAY
		glDisableClientState(GL_COLOR_ARRAY);

        // glColor4ub isn't implement on some android devices
		// glColor4ub( m_tColor.r, m_tColor.g, m_tColor.b, m_cOpacity);
        glColor4f(((GLfloat)m_tColor.r) / 255, ((GLfloat)m_tColor.g) / 255, ((GLfloat)m_tColor.b) / 255, ((GLfloat)m_cOpacity) / 255);

		bool newBlend = (m_tBlendFunc.src != CC_BLEND_SRC || m_tBlendFunc.dst != CC_BLEND_DST);
		if(newBlend)
        {
			glBlendFunc( m_tBlendFunc.src, m_tBlendFunc.dst );
		}

		m_pTextureAtlas->drawNumberOfQuads(m_sString.length());

		if( newBlend )
			glBlendFunc(CC_BLEND_SRC, CC_BLEND_DST);

		// is this chepear than saving/restoring color state ?
		// XXX: There is no need to restore the color to (255,255,255,255). Objects should use the color
		// XXX: that they need
		//	glColor4ub( 255, 255, 255, 255);

		// Restore Default GL state. Enable GL_COLOR_ARRAY
		glEnableClientState(GL_COLOR_ARRAY);


#if CC_LABELATLAS_DEBUG_DRAW
		CCSize s = this->getContentSize();
		CCPoint vertices[4]={
			ccp(0,0),ccp(s.width,0),
			ccp(s.width,s.height),ccp(0,s.height),
		};
		ccDrawPoly(vertices, 4, true);
#endif // CC_LABELATLAS_DEBUG_DRAW

	}
//-------------------------------------------------------------------------
void FKCW_RichHtml_RichAtlas::draw()
{
	if ( m_dirty )
	{
		this->updateRichRenderData();
	}

	CCAtlasNode::draw();

	if( g_bIsFKCWRichHtmlDebug )
	{
		// АќЮЇКа
		const CCSize& s = this->getContentSize();
		CCPoint vertices[4]={
			ccp(0,0),ccp(s.width,0),
			ccp(s.width,s.height),ccp(0,s.height),
		};
		ccDrawColor4B(0x00, 0xff, 0x00, 0xff);
		ccDrawPoly(vertices, 4, true);
	}
}
Ejemplo n.º 10
0
void YUVSprite::draw()
{
    CC_PROFILER_START_CATEGORY(kCCProfilerCategorySprite, "YUVSprite - draw");
    
    CCAssert(!m_pobBatchNode, "If YUVSprite is being rendered by CCSpriteBatchNode, YUVSprite#draw SHOULD NOT be called");
   // CC_NODE_DRAW_SETUP();
    ccGLBlendFunc( m_sBlendFunc.src, m_sBlendFunc.dst );

    if(_prog){
        _prog->use();
        _prog->setUniformsForBuiltins();
    }
    if(textureDone){
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, id_y);
        glUniform1i(textureUniformY, 0);
        
        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, id_u);
        glUniform1i(textureUniformU, 1);
        
        glActiveTexture(GL_TEXTURE2);
        glBindTexture(GL_TEXTURE_2D, id_v);
        glUniform1i(textureUniformV, 2);
        
        glUniform1f(borderUniformY,_border[0]);
        glUniform1f(borderUniformU,_border[1]);
        glUniform1f(borderUniformV,_border[2]);
    }
    //ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTex );
    
#define kQuadSize sizeof(m_sQuad.bl)
#ifdef EMSCRIPTEN
    long offset = 0;
    setGLBufferData(&m_sQuad, 4 * kQuadSize, 0);
#else
    long offset = (long)&m_sQuad;
#endif // EMSCRIPTEN
    CHECK_GL_ERROR_DEBUG();
    
    GLfloat square[8];
    CCSize s = this->getTextureRect().size;
    CCPoint offsetPix = this->getOffsetPosition();
    
    square[0] = offsetPix.x;
    square[1] = offsetPix.y;
    
    square[2] = offsetPix.x+s.width;
    square[3] = offsetPix.y;
    
    square[6] = offsetPix.x+s.width;
    square[7] = offsetPix.y+s.height;
    
    square[4] = offsetPix.x;
    square[5] = offsetPix.y+s.height;

    glVertexAttribPointer(ATTRIB_VERTEX, 2, GL_FLOAT, 0, 0, square);
    glEnableVertexAttribArray(ATTRIB_VERTEX);
    
    glVertexAttribPointer(ATTRIB_TEXTURE, 2, GL_FLOAT, 0, 0, coordVertices);
    glEnableVertexAttribArray(ATTRIB_TEXTURE);

    /*
    // 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();
#if CC_SPRITE_DEBUG_DRAW == 1
    // draw bounding box
    CCPoint vertices[4]={
        ccp(m_sQuad.tl.vertices.x,m_sQuad.tl.vertices.y),
        ccp(m_sQuad.bl.vertices.x,m_sQuad.bl.vertices.y),
        ccp(m_sQuad.br.vertices.x,m_sQuad.br.vertices.y),
        ccp(m_sQuad.tr.vertices.x,m_sQuad.tr.vertices.y),
    };
    ccDrawPoly(vertices, 4, true);
#elif CC_SPRITE_DEBUG_DRAW == 2
    // draw texture box
    CCSize s = this->getTextureRect().size;
    CCPoint offsetPix = this->getOffsetPosition();
    CCPoint vertices[4] = {
        ccp(offsetPix.x,offsetPix.y), ccp(offsetPix.x+s.width,offsetPix.y),
        ccp(offsetPix.x+s.width,offsetPix.y+s.height), ccp(offsetPix.x,offsetPix.y+s.height)
    };
    ccDrawPoly(vertices, 4, true);
#endif // CC_SPRITE_DEBUG_DRAW
    CC_INCREMENT_GL_DRAWS(1);
    
    CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "YUVSprite - draw");
}
Ejemplo n.º 11
0
void ccDrawPoly(const CCPoint *poli, int numberOfPoints, bool closePolygon){
	ccDrawPoly(poli,numberOfPoints,closePolygon,false);
}
Ejemplo n.º 12
0
void CAView::updateTransform()
{
    // Recursively iterate over children
    if(m_pobImage && isDirty() )
    {
        
        // If it is not visible, or one of its ancestors is not visible, then do nothing:
        if( !m_bVisible || ( m_pSuperview && m_pSuperview != m_pobBatchView && m_pSuperview->m_bShouldBeHidden) )
        {
            m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = vertex3(0,0,0);
            m_bShouldBeHidden = true;
        }
        else
        {
            m_bShouldBeHidden = false;
            
            if( !m_pSuperview || m_pSuperview == m_pobBatchView)
            {
                m_transformToBatch = nodeToParentTransform();
            }
            else
            {
                m_transformToBatch = CATransformationConcat( nodeToParentTransform() , m_pSuperview->m_transformToBatch );
            }

            DSize size = m_obContentSize;
            
            float x1 = 0;
            float y1 = 0;
            
            float x = m_transformToBatch.tx;
            float y = m_transformToBatch.ty;
            
            float cr = m_transformToBatch.a;
            float sr = m_transformToBatch.b;
            float cr2 = m_transformToBatch.d;
            float sr2 = -m_transformToBatch.c;
            
            x1 = x1 * cr - y1 * sr2 + x;
            y1 = x1 * sr + y1 * cr2 + y;
            
            x1 = RENDER_IN_SUBPIXEL(x1);
            y1 = RENDER_IN_SUBPIXEL(y1);
            
            float x2 = x1 + size.width;
            float y2 = y1 + size.height;

            m_sQuad.bl.vertices = vertex3( x1, y1, m_fVertexZ );
            m_sQuad.br.vertices = vertex3( x2, y1, m_fVertexZ );
            m_sQuad.tl.vertices = vertex3( x1, y2, m_fVertexZ );
            m_sQuad.tr.vertices = vertex3( x2, y2, m_fVertexZ );
        }
        
        if (m_pobImageAtlas)
		{
            m_pobImageAtlas->updateQuad(&m_sQuad, m_uAtlasIndex);
        }
        
        m_bRecursiveDirty = false;
        setDirty(false);
    }
    
    if (!m_obSubviews.empty())
    {
        CAVector<CAView*>::iterator itr;
        for (itr=m_obSubviews.begin(); itr!=m_obSubviews.end(); itr++)
            (*itr)->updateTransform();
    }
    
#if CC_SPRITE_DEBUG_DRAW
    // draw bounding box
    DPoint vertices[4] =
    {
        DPoint( m_sQuad.bl.vertices.x, m_sQuad.bl.vertices.y ),
        DPoint( m_sQuad.br.vertices.x, m_sQuad.br.vertices.y ),
        DPoint( m_sQuad.tr.vertices.x, m_sQuad.tr.vertices.y ),
        DPoint( m_sQuad.tl.vertices.x, m_sQuad.tl.vertices.y ),
    };
    ccDrawPoly(vertices, 4, true);
#endif

}
Ejemplo n.º 13
0
void GAFSprite::updateTransform(void)
{
	CCAssert( m_pobBatchNode, "updateTransform is only valid when CCSprite is being rendered using an CCSpriteBatchNode");
		
    // recalculate matrix only if it is dirty
    if( isDirty() ) {
		
        // If it is not visible, or one of its ancestors is not visible, then do nothing:
        if( !m_bVisible || ( m_pParent && m_pParent != (CCSprite*)m_pobBatchNode && ((CCSprite*)m_pParent)->m_bShouldBeHidden) )
        {
            m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = vertex3(0,0,0);
            m_bShouldBeHidden = true;
        }
        else
        {
            m_bShouldBeHidden = false;
			
            if( ! m_pParent || m_pParent == (CCSprite*)m_pobBatchNode )
            {
                m_transformToBatch = nodeToParentTransform();
            }
            else
            {
                CCAssert( dynamic_cast<CCSprite*>(m_pParent), "Logic error in CCSprite. Parent must be a CCSprite");
                m_transformToBatch = CCAffineTransformConcat( nodeToParentTransform() , ((CCSprite*)m_pParent)->m_transformToBatch );
            }
			
            //
            // calculate the Quad based on the Affine Matrix
            //
			
            CCSize size = m_obRect.size;
			
			// x1, x2, y1, y2 are changed (comapring to CCSprite) to place Sprite at center
            float x1 = m_obOffsetPosition.x - size.width / 2;
            float y1 = m_obOffsetPosition.y - size.height / 2;
			
            float x2 = x1 + size.width;
            float y2 = y1 + size.height;
            float x = m_transformToBatch.tx;
            float y = m_transformToBatch.ty;
			
            float cr = m_transformToBatch.a;
            float sr = m_transformToBatch.b;
            float cr2 = m_transformToBatch.d;
            float sr2 = -m_transformToBatch.c;
            float ax = x1 * cr - y1 * sr2 + x;
            float ay = x1 * sr + y1 * cr2 + y;
			
            float bx = x2 * cr - y1 * sr2 + x;
            float by = x2 * sr + y1 * cr2 + y;
			
            float cx = x2 * cr - y2 * sr2 + x;
            float cy = x2 * sr + y2 * cr2 + y;
			
            float dx = x1 * cr - y2 * sr2 + x;
            float dy = x1 * sr + y2 * cr2 + y;
			
            m_sQuad.bl.vertices = vertex3( RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), m_fVertexZ );
            m_sQuad.br.vertices = vertex3( RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), m_fVertexZ );
            m_sQuad.tl.vertices = vertex3( RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), m_fVertexZ );
            m_sQuad.tr.vertices = vertex3( RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), m_fVertexZ );
        }
		
        // MARMALADE CHANGE: ADDED CHECK FOR NULL, TO PERMIT SPRITES WITH NO BATCH NODE / TEXTURE ATLAS
        if (m_pobTextureAtlas)
		{
            m_pobTextureAtlas->updateQuad(&m_sQuad, m_uAtlasIndex);
        }
		
        m_bRecursiveDirty = false;
        setDirty(false);
    }
	
    // MARMALADE CHANGED
    // recursively iterate over children
	/*    if( m_bHasChildren )
	 {
	 // MARMALADE: CHANGED TO USE CCNode*
	 // NOTE THAT WE HAVE ALSO DEFINED virtual CCNode::updateTransform()
	 arrayMakeObjectsPerformSelector(m_pChildren, updateTransform, CCSprite*);
	 }*/
    CCNode::updateTransform();
	
#if CC_SPRITE_DEBUG_DRAW
    // draw bounding box
    CCPoint vertices[4] = {
        ccp( m_sQuad.bl.vertices.x, m_sQuad.bl.vertices.y ),
        ccp( m_sQuad.br.vertices.x, m_sQuad.br.vertices.y ),
        ccp( m_sQuad.tr.vertices.x, m_sQuad.tr.vertices.y ),
        ccp( m_sQuad.tl.vertices.x, m_sQuad.tl.vertices.y ),
    };
    ccDrawPoly(vertices, 4, true);
#endif // CC_SPRITE_DEBUG_DRAW
}
Ejemplo n.º 14
0
void CCSquirmAnimNode::draw()
{
	CCAssert(m_pobTexture != 0 && m_maskTexture != 0, "CCSquirmAnimNode::draw(), textures mustn't be null!");
	CC_PROFILER_START_CATEGORY(kCCProfilerCategorySprite, "CCSprite - draw");

	// 如果顶点数据需要刷新,就刷新之
	if(m_vertices_dirty)
	{
		rebuildVertices();
	}

	CC_NODE_DRAW_SETUP();

	ccGLBlendFunc( m_sBlendFunc.src, m_sBlendFunc.dst );

	ccGLBindTexture2DN(0, m_pobTexture->getName());
	ccGLBindTexture2DN(1, m_maskTexture->getName());

	//
	// Attributes
	//

	ccGLEnableVertexAttribs( kCCVertexAttribFlag_PosColorTexTex );

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

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

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

	diff = offsetof(ccV3F_C4B_T2Fx2, texCoords1);
	glVertexAttribPointer(kCCVertexAttrib_TexCoords1, 2, GL_FLOAT, GL_FALSE, kQuadSize, (void*)(offset + diff));

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


	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	CHECK_GL_ERROR_DEBUG();


#if CC_SPRITE_DEBUG_DRAW == 1
	// draw bounding box
	CCPoint vertices[4]={
		ccp(m_sQuad.tl.vertices.x,m_sQuad.tl.vertices.y),
		ccp(m_sQuad.bl.vertices.x,m_sQuad.bl.vertices.y),
		ccp(m_sQuad.br.vertices.x,m_sQuad.br.vertices.y),
		ccp(m_sQuad.tr.vertices.x,m_sQuad.tr.vertices.y),
	};
	ccDrawPoly(vertices, 4, true);
#elif CC_SPRITE_DEBUG_DRAW == 2
	// draw texture box
	CCSize s = this->getTextureRect().size;
	CCPoint offsetPix = this->getOffsetPosition();
	CCPoint vertices[4] = {
		ccp(offsetPix.x,offsetPix.y), ccp(offsetPix.x+s.width,offsetPix.y),
		ccp(offsetPix.x+s.width,offsetPix.y+s.height), ccp(offsetPix.x,offsetPix.y+s.height)
	};
	ccDrawPoly(vertices, 4, true);
#endif // CC_SPRITE_DEBUG_DRAW

	CC_INCREMENT_GL_DRAWS(1);

	CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "CCSquirmAnimNode - draw");
}
Ejemplo n.º 15
0
void CCSkeleton::draw () {
	CC_NODE_DRAW_SETUP();

	ccGLBlendFunc(blendFunc.src, blendFunc.dst);
	ccColor3B color = getColor();
	skeleton->r = color.r / (float)255;
	skeleton->g = color.g / (float)255;
	skeleton->b = color.b / (float)255;
	skeleton->a = getOpacity() / (float)255;

	CCTextureAtlas* textureAtlas = 0;
	ccV3F_C4B_T2F_Quad quad;
	quad.tl.vertices.z = 0;
	quad.tr.vertices.z = 0;
	quad.bl.vertices.z = 0;
	quad.br.vertices.z = 0;
	for (int i = 0, n = skeleton->slotCount; i < n; i++) {
		Slot* slot = skeleton->slots[i];
		if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
		RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
		CCTextureAtlas* regionTextureAtlas = (CCTextureAtlas*)((AtlasRegion*)attachment->rendererObject)->page->rendererObject;
		if (regionTextureAtlas != textureAtlas) {
			if (textureAtlas) {
				textureAtlas->drawQuads();
				textureAtlas->removeAllQuads();
			}
		}
		textureAtlas = regionTextureAtlas;
		if (textureAtlas->getCapacity() == textureAtlas->getTotalQuads() &&
			!textureAtlas->resizeCapacity(textureAtlas->getCapacity() * 2)) return;
		RegionAttachment_updateQuad(attachment, slot, &quad);
		textureAtlas->updateQuad(&quad, textureAtlas->getTotalQuads());
	}
	if (textureAtlas) {
		textureAtlas->drawQuads();
		textureAtlas->removeAllQuads();
	}

	if (debugSlots) {
		// Slots.
		ccDrawColor4B(0, 0, 255, 255);
		glLineWidth(1);
		CCPoint points[4];
		ccV3F_C4B_T2F_Quad quad;
		for (int i = 0, n = skeleton->slotCount; i < n; i++) {
			Slot* slot = skeleton->slots[i];
			if (!slot->attachment || slot->attachment->type != ATTACHMENT_REGION) continue;
			RegionAttachment* attachment = (RegionAttachment*)slot->attachment;
			RegionAttachment_updateQuad(attachment, slot, &quad);
			points[0] = ccp(quad.bl.vertices.x, quad.bl.vertices.y);
			points[1] = ccp(quad.br.vertices.x, quad.br.vertices.y);
			points[2] = ccp(quad.tr.vertices.x, quad.tr.vertices.y);
			points[3] = ccp(quad.tl.vertices.x, quad.tl.vertices.y);
			ccDrawPoly(points, 4, true);
		}
	}
	if (debugBones) {
		// Bone lengths.
		glLineWidth(2);
		ccDrawColor4B(255, 0, 0, 255);
		for (int i = 0, n = skeleton->boneCount; i < n; i++) {
			Bone *bone = skeleton->bones[i];
			float x = bone->data->length * bone->m00 + bone->worldX;
			float y = bone->data->length * bone->m10 + bone->worldY;
			ccDrawLine(ccp(bone->worldX, bone->worldY), ccp(x, y));
		}
		// Bone origins.
		ccPointSize(4);
		ccDrawColor4B(0, 0, 255, 255); // Root bone is blue.
		for (int i = 0, n = skeleton->boneCount; i < n; i++) {
			Bone *bone = skeleton->bones[i];
			ccDrawPoint(ccp(bone->worldX, bone->worldY));
			if (i == 0) ccDrawColor4B(0, 255, 0, 255);
		}
	}
}
Ejemplo n.º 16
0
void SpriteMask::draw()
{
	if (!_isSetMask)   //沒有設定就直接用預設方法
	{
		CCSprite::draw();
		return;
	}

	CC_PROFILER_START_CATEGORY(kProfilerCategorySprite, "CCSprite - draw");

	CCASSERT(!_batchNode, "If Sprite is being rendered by SpriteBatchNode, Sprite#draw SHOULD NOT be called");

	CC_NODE_DRAW_SETUP();

	GL::blendFunc(_blendFunc.src, _blendFunc.dst);

	GL::bindTexture2D(_texture->getName());
	GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POS_COLOR_TEX);

	if (_texture != NULL) {
		ccGLBindTexture2D(_texture->getName());
	} else {
		ccGLBindTexture2D(0);
	}
	
	//mask 設定 設定使用mask貼圖
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, _maskTexture->getName());
	glUniform1i(_maskLocation, 1);
	glUniform2f(_offsetLocation, offsetWithPosition.x, offsetWithPosition.y);

#define kQuadSize sizeof(_quad.bl)
#ifdef EMSCRIPTEN
	long offset = 0;
	setGLBufferData(&_quad, 4 * kQuadSize, 0);
#else
	long offset = (long)&_quad;
#endif // EMSCRIPTEN

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

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

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


	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	CHECK_GL_ERROR_DEBUG();


#if CC_SPRITE_DEBUG_DRAW == 1
	// draw bounding box
	Point vertices[4] = {
		Point(_quad.tl.vertices.x, _quad.tl.vertices.y),
		Point(_quad.bl.vertices.x, _quad.bl.vertices.y),
		Point(_quad.br.vertices.x, _quad.br.vertices.y),
		Point(_quad.tr.vertices.x, _quad.tr.vertices.y),
	};
	ccDrawPoly(vertices, 4, true);
#elif CC_SPRITE_DEBUG_DRAW == 2
	// draw texture box
	Size s = this->getTextureRect().size;
	Point offsetPix = this->getOffsetPosition();
	Point vertices[4] = {
		Point(offsetPix.x, offsetPix.y), Point(offsetPix.x + s.width, offsetPix.y),
		Point(offsetPix.x + s.width, offsetPix.y + s.height), Point(offsetPix.x, offsetPix.y + s.height)
	};
	ccDrawPoly(vertices, 4, true);
#endif // CC_SPRITE_DEBUG_DRAW

	CC_INCREMENT_GL_DRAWS(1);

	glActiveTexture(GL_TEXTURE0);  //must set to texture0

	CC_PROFILER_STOP_CATEGORY(kProfilerCategorySprite, "CCSprite - draw");
}
Ejemplo n.º 17
0
void Skeleton2D_BoneDisplay::updateTransform(void)
{
	CCAssert(m_pobBatchNode, "updateTransform is only valid when CCSprite is being rendered using an CCSpriteBatchNode");

	// recalculate matrix only if it is dirty
	if( isDirty() ) {

		// If it is not visible, or one of its ancestors is not visible, then do nothing:
		//if( !IsVisable() || ( m_pParent && m_pParent != m_pobBatchNode /*&& ((CCSprite*)m_pParent)->m_bShouldBeHidden*/) )
		if (false)
		{
			m_sQuad.br.vertices = m_sQuad.tl.vertices = m_sQuad.tr.vertices = m_sQuad.bl.vertices = vertex3(0,0,0);
			m_bShouldBeHidden = true;
		}
		else 
		{//
			CCAffineTransform tm;
			m_bShouldBeHidden = false;

			tm = nodeToParentTransform();
			//
			// calculate the Quad based on the Affine Matrix
			//

			CCSize size = m_obRect.size;

			float x1 = m_obOffsetPosition.x;
			float y1 = m_obOffsetPosition.y;

			float x2 = x1 + size.width;
			float y2 = y1 + size.height;
			float x = tm.tx;
			float y = tm.ty;

			float cr = tm.a;
			float sr = tm.b;
			float cr2 = tm.d;
			float sr2 = -tm.c;
			float ax = x1 * cr - y1 * sr2 + x;
			float ay = x1 * sr + y1 * cr2 + y;

			float bx = x2 * cr - y1 * sr2 + x;
			float by = x2 * sr + y1 * cr2 + y;

			float cx = x2 * cr - y2 * sr2 + x;
			float cy = x2 * sr + y2 * cr2 + y;

			float dx = x1 * cr - y2 * sr2 + x;
			float dy = x1 * sr + y2 * cr2 + y;

			ax*=-1.0f;ay*=-1.0f;bx*=-1.0f;by*=-1.0f;cx*=-1.0f;cy*=-1.0f;dx*=-1.0f;dy*=-1.0f;

			m_sQuad.bl.vertices = vertex3( RENDER_IN_SUBPIXEL(ax), RENDER_IN_SUBPIXEL(ay), m_fVertexZ );
			m_sQuad.br.vertices = vertex3( RENDER_IN_SUBPIXEL(bx), RENDER_IN_SUBPIXEL(by), m_fVertexZ );
			m_sQuad.tl.vertices = vertex3( RENDER_IN_SUBPIXEL(dx), RENDER_IN_SUBPIXEL(dy), m_fVertexZ );
			m_sQuad.tr.vertices = vertex3( RENDER_IN_SUBPIXEL(cx), RENDER_IN_SUBPIXEL(cy), m_fVertexZ );
		}

		m_pobTextureAtlas->updateQuad(&m_sQuad, m_uAtlasIndex);
		m_bRecursiveDirty = false;
		setDirty(false);
	}

	// recursively iterate over children
	if( m_bHasChildren ) 
	{
		arrayMakeObjectsPerformSelector(m_pChildren, updateTransform, CCSprite*);
	}
#if CC_SPRITE_DEBUG_DRAW
	// draw bounding box
	CCPoint vertices[4] = {
		ccp( m_sQuad.bl.vertices.x, m_sQuad.bl.vertices.y ),
		ccp( m_sQuad.br.vertices.x, m_sQuad.br.vertices.y ),
		ccp( m_sQuad.tr.vertices.x, m_sQuad.tr.vertices.y ),
		ccp( m_sQuad.tl.vertices.x, m_sQuad.tl.vertices.y ),
	};
	ccDrawPoly(vertices, 4, true);
#endif // CC_SPRITE_DEBUG_DRAW
}
Ejemplo n.º 18
0
void DrawPrimitivesTest::draw()
{
	CCLayer::draw();

    CCSize s = CCDirector::sharedDirector()->getWinSize();
	
	// draw a simple line
	// The default state is:
	// Line Width: 1
	// color: 255,255,255,255 (white, non-transparent)
	// Anti-Aliased
	glEnable(GL_LINE_SMOOTH);
	ccDrawLine( CCPointMake(0, 0), CCPointMake(s.width, s.height) );
	
	// line: color, width, aliased
	// glLineWidth > 1 and GL_LINE_SMOOTH are not compatible
	// GL_SMOOTH_LINE_WIDTH_RANGE = (1,1) on iPhone
	glDisable(GL_LINE_SMOOTH);
	glLineWidth( 5.0f );
	/*glColor4ub(255,0,0,255);*/
	glColor4f(1.0, 0.0, 0.0, 1.0);
	ccDrawLine( CCPointMake(0, s.height), CCPointMake(s.width, 0) );

	// TIP:
	// If you are going to use always the same color or width, you don't
	// need to call it before every draw
	//
	// Remember: OpenGL is a state-machine.
	
	// draw big point in the center
	glPointSize(64);
	/*glColor4ub(0,0,255,128);*/
	glColor4f(0.0, 0.0, 1.0, 0.5);
	ccDrawPoint( CCPointMake(s.width / 2, s.height / 2) );
	
	// draw 4 small points
	CCPoint points[] = { CCPointMake(60,60), CCPointMake(70,70), CCPointMake(60,70), CCPointMake(70,60) };
	glPointSize(4);
	/*glColor4ub(0,255,255,255);*/
	glColor4f(0.0, 1.0, 1.0, 1.0);
	ccDrawPoints( points, 4);
	
	// draw a green circle with 10 segments
	glLineWidth(16);
	/*glColor4ub(0, 255, 0, 255);*/
	glColor4f(0.0, 1.0, 0.0, 1.0);
	ccDrawCircle( CCPointMake(s.width/2,  s.height/2), 100, 0, 10, false);

	// draw a green circle with 50 segments with line to center
	glLineWidth(2);
	/*glColor4ub(0, 255, 255, 255);*/
	glColor4f(0.0, 1.0, 1.0, 1.0);
	ccDrawCircle( CCPointMake(s.width/2, s.height/2), 50, CC_DEGREES_TO_RADIANS(90), 50, true);	
	
	// open yellow poly
	/*glColor4ub(255, 255, 0, 255);*/
	glColor4f(1.0, 1.0, 0.0, 1.0);
	glLineWidth(10);
	CCPoint vertices[] = { CCPointMake(0,0), CCPointMake(50,50), CCPointMake(100,50), CCPointMake(100,100), CCPointMake(50,100) };
	ccDrawPoly( vertices, 5, false);
	
	// closed purble poly
	/*glColor4ub(255, 0, 255, 255);*/
	glColor4f(1.0, 0.0, 1.0, 1.0);
	glLineWidth(2);
	CCPoint vertices2[] = { CCPointMake(30,130), CCPointMake(30,230), CCPointMake(50,200) };
	ccDrawPoly( vertices2, 3, true);
	
	// draw quad bezier path
	ccDrawQuadBezier(CCPointMake(0,s.height), CCPointMake(s.width/2,s.height/2), CCPointMake(s.width,s.height), 50);

	// draw cubic bezier path
	ccDrawCubicBezier(CCPointMake(s.width/2, s.height/2), CCPointMake(s.width/2+30,s.height/2+50), CCPointMake(s.width/2+60,s.height/2-50),CCPointMake(s.width, s.height/2),100);

	
	// restore original values
	glLineWidth(1);
	/*glColor4ub(255,255,255,255);*/
	glColor4f(1.0, 1.0, 1.0, 1.0);
	glPointSize(1); 
}
Ejemplo n.º 19
0
void CAView::draw()
{
    m_uZLevel = CAApplication::getApplication()->getCurrentNumberOfDraws();
    
    CC_RETURN_IF(m_pobImage == NULL);
    CC_RETURN_IF(m_pShaderProgram == NULL);
    
    CC_NODE_DRAW_SETUP();
    
    ccGLBlendFunc(m_sBlendFunc.src, m_sBlendFunc.dst);
    ccGLBindTexture2D(m_pobImage->getName());
    ccGLEnableVertexAttribs(kCCVertexAttribFlag_PosColorTex);
    
#define kQuadSize sizeof(m_sQuad.bl)
#ifdef EMSCRIPTEN
    
    long offset = 0;
    setGLBufferData(&m_sQuad, 4 * kQuadSize, 0);
    
#else
    
    long offset = (long)&m_sQuad;
    
#endif
    
    // 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);
        
#if CC_SPRITE_DEBUG_DRAW
    // draw bounding box
    DPoint vertices[4]=
    {
        DPoint(m_sQuad.tl.vertices.x, m_sQuad.tl.vertices.y),
        DPoint(m_sQuad.bl.vertices.x, m_sQuad.bl.vertices.y),
        DPoint(m_sQuad.br.vertices.x, m_sQuad.br.vertices.y),
        DPoint(m_sQuad.tr.vertices.x, m_sQuad.tr.vertices.y),
    };
    ccDrawPoly(vertices, 4, true);
#endif // CC_SPRITE_DEBUG_DRAW

    CC_PROFILER_STOP_CATEGORY(kCCProfilerCategorySprite, "CAView - draw");
}