void RenderTexture::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { // override visit. // Don't call visit on its children if (!_visible) { return; } uint32_t flags = processParentFlags(parentTransform, parentFlags); Director* director = Director::getInstance(); // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); _sprite->visit(renderer, _modelViewTransform, flags); draw(renderer, _modelViewTransform, flags); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _orderOfArrival = 0; }
void BatchNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { // quick return if not visible. children won't be drawn. if (!_visible || !isVisitableByVisitingCamera()) { return; } uint32_t flags = processParentFlags(parentTransform, parentFlags); // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); sortAllChildren(); draw(renderer, _modelViewTransform, flags); // reset for next frame _orderOfArrival = 0; director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void TMXIsoObjectsTest::onDraw(const Mat4 &transform, bool transformUpdated) { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); auto map = (TMXTiledMap*) getChildByTag(kTagTileMap); auto pos = map->getPosition(); auto group = map->getObjectGroup("Object Group 1"); auto& objects = group->getObjects(); for (auto& obj : objects) { ValueMap& dict = obj.asValueMap(); float x = dict["x"].asFloat(); float y = dict["y"].asFloat(); float width = dict["width"].asFloat(); float height = dict["height"].asFloat(); glLineWidth(3); DrawPrimitives::drawLine( pos + Vec2(x,y), pos + Vec2(x+width,y) ); DrawPrimitives::drawLine( pos + Vec2(x+width,y), pos + Vec2(x+width,y+height) ); DrawPrimitives::drawLine( pos + Vec2(x+width,y+height), pos + Vec2(x,y+height) ); DrawPrimitives::drawLine( pos + Vec2(x,y+height), pos + Vec2(x,y) ); glLineWidth(1); } director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void Armature::visit(cocos2d::Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { // quick return if not visible. children won't be drawn. if (!_visible) { return; } uint32_t flags = processParentFlags(parentTransform, parentFlags); if (isVisitableByVisitingCamera()) { // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when setting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); sortAllChildren(); draw(renderer, _modelViewTransform, flags); // FIX ME: Why need to set _orderOfArrival to 0?? // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920 // setOrderOfArrival(0); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } }
// override visit. // Don't call visit on it's children void ParticleBatchNode::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { // CAREFUL: // This visit is almost identical to Node#visit // with the exception that it doesn't call visit on it's children // // The alternative is to have a void Sprite#visit, but // although this is less maintainable, is faster // if (!_visible) { return; } uint32_t flags = processParentFlags(parentTransform, parentFlags); if (isVisitableByVisitingCamera()) { // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); draw(renderer, _modelViewTransform, flags); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); } }
void RenderTexture::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { // override visit. // Don't call visit on its children if (!_visible || !isVisitableByVisitingCamera()) { return; } uint32_t flags = processParentFlags(parentTransform, parentFlags); Director* director = Director::getInstance(); // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); _sprite->visit(renderer, _modelViewTransform, flags); draw(renderer, _modelViewTransform, flags); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); // FIX ME: Why need to set _orderOfArrival to 0?? // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920 // setOrderOfArrival(0); }
void RenderTexture::visit(Renderer *renderer, const Mat4 &parentTransform, bool parentTransformUpdated) { // override visit. // Don't call visit on its children if (!_visible) { return; } bool dirty = parentTransformUpdated || _transformUpdated; if(dirty) _modelViewTransform = transform(parentTransform); _transformUpdated = false; Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); _sprite->visit(renderer, _modelViewTransform, dirty); draw(renderer, _modelViewTransform, dirty); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _orderOfArrival = 0; }
void RenderTexture::end() { _endCommand.init(_globalZOrder); _endCommand.func = CC_CALLBACK_0(RenderTexture::onEnd, this); Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); Renderer *renderer = director->getRenderer(); renderer->addCommand(&_endCommand); renderer->popGroup(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void Armature::visit(cocos2d::Renderer *renderer, const Mat4 &parentTransform, bool parentTransformUpdated) { // quick return if not visible. children won't be drawn. if (!_visible) { return; } bool dirty = parentTransformUpdated || _transformUpdated; if(dirty) _modelViewTransform = transform(parentTransform); _transformUpdated = false; // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); sortAllChildren(); draw(renderer, _modelViewTransform, dirty); // reset for next frame _orderOfArrival = 0; director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
// override visit. // Don't call visit on it's children void ParticleBatchNode::visit(Renderer *renderer, const Matrix &parentTransform, bool parentTransformUpdated) { // CAREFUL: // This visit is almost identical to Node#visit // with the exception that it doesn't call visit on it's children // // The alternative is to have a void Sprite#visit, but // although this is less maintainable, is faster // if (!_visible) { return; } bool dirty = parentTransformUpdated || _transformUpdated; if(dirty) _modelViewTransform = transform(parentTransform); _transformUpdated = false; // IMPORTANT: // To ease the migration to v3.0, we still support the Matrix stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); draw(renderer, _modelViewTransform, dirty); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void SnakeMapLayer::onDraw(const Mat4& transform, uint32_t flags) { Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); #ifdef DEBUG_DRAW glLineWidth(1); for (int i = 0; i < MAPWIDTH; ++i) { for (int j = 0; j < MAPHEIGHT; ++j) { auto color = Color4F::BLACK; auto type = getGridType(Vec2(i, j)); if (type == eType_Snake) color = Color4F(0.5f, 0.5f, 1, 0.8f); else if (type == eType_Food) color = Color4F(0, 1, 0, 0.8f); else if (type == eType_Apple) color = Color4F(1, 0, 0, 0.8f); else if (type == eType_Star) color = Color4F(1, 1, 0, 0.8f); else if (type == eType_Ball) color = Color4F(0, 0, 1, 0.8f); if (color != Color4F::BLACK) { auto x = VisibleRect::getGridLength() * i + VisibleRect::getVisibleRect().origin.x; auto y = VisibleRect::getGridLength() * j + VisibleRect::getVisibleRect().origin.y; auto x1 = x + VisibleRect::getGridLength(); auto y1 = y + VisibleRect::getGridLength(); Vec2 filledVertices[] = { Vec2(x, y), Vec2(x1, y), Vec2(x1, y1), Vec2(x, y1) }; DrawPrimitives::drawSolidPoly(filledVertices, 4, color); CHECK_GL_ERROR_DEBUG(); } } } //update the debug label content char tmp[50]; auto speedLabel = dynamic_cast<Label*>(getChildByTag(eID_SpeedLabel)); if (speedLabel) { sprintf(tmp, "Speed: %f", m_pSnake->getSpeed()); speedLabel->setString(tmp); } auto scoreRateLabel = dynamic_cast<Label*>(getChildByTag(eID_ScoreRateLabel)); if (scoreRateLabel) { sprintf(tmp, "ScoreRate: %f", m_pSnake->getScoreRate()); scoreRateLabel->setString(tmp); } #endif //end draw director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void BillBoard::visit(Renderer *renderer, const Mat4& parentTransform, uint32_t parentFlags) { // quick return if not visible. children won't be drawn. if (!_visible) { return; } bool visibleByCamera = isVisitableByVisitingCamera(); // quick return if not visible by camera and has no children. if (!visibleByCamera && _children.empty()) { return; } uint32_t flags = processParentFlags(parentTransform, parentFlags); //Add 3D flag so all the children will be rendered as 3D object flags |= FLAGS_RENDER_AS_3D; //Update Billboard transform bool dirty = calculateBillboardTransform(); if(dirty) { flags |= FLAGS_TRANSFORM_DIRTY; } Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); int i = 0; if(!_children.empty()) { sortAllChildren(); // draw children zOrder < 0 for(auto size = _children.size(); i < size; ++i) { auto node = _children.at(i); if (node && node->getLocalZOrder() < 0) node->visit(renderer, _modelViewTransform, flags); else break; } // self draw if (visibleByCamera) this->draw(renderer, _modelViewTransform, flags); for(auto it=_children.cbegin()+i, itCend = _children.cend(); it != itCend; ++it) (*it)->visit(renderer, _modelViewTransform, flags); } else if (visibleByCamera) { this->draw(renderer, _modelViewTransform, flags); } director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void ScrollView::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { // quick return if not visible if (!isVisible() || !isVisitableByVisitingCamera()) { return; } uint32_t flags = processParentFlags(parentTransform, parentFlags); // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); this->beforeDraw(); bool visibleByCamera = isVisitableByVisitingCamera(); if (!_children.empty()) { int i=0; // draw children zOrder < 0 for( ; i < _children.size(); i++ ) { Node *child = _children.at(i); if ( child->getLocalZOrder() < 0 ) { child->visit(renderer, _modelViewTransform, flags); } else { break; } } // this draw if (visibleByCamera) this->draw(renderer, _modelViewTransform, flags); // draw children zOrder >= 0 for( ; i < _children.size(); i++ ) { Node *child = _children.at(i); child->visit(renderer, _modelViewTransform, flags); } } else if (visibleByCamera) { this->draw(renderer, _modelViewTransform, flags); } this->afterDraw(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void Label::visit(Renderer *renderer, const Mat4 &parentTransform, uint32_t parentFlags) { if (! _visible || _originalUTF8String.empty()) { return; } if (_systemFontDirty) { updateFont(); } if (_contentDirty) { updateContent(); } uint32_t flags = processParentFlags(parentTransform, parentFlags); if (_shadowEnabled && _shadowBlurRadius <= 0 && (_shadowDirty || (flags & FLAGS_DIRTY_MASK))) { _position.x += _shadowOffset.width; _position.y += _shadowOffset.height; _transformDirty = _inverseDirty = true; _shadowTransform = transform(parentTransform); _position.x -= _shadowOffset.width; _position.y -= _shadowOffset.height; _transformDirty = _inverseDirty = true; _shadowDirty = false; } // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); if (_textSprite) { drawTextSprite(renderer, flags); } else { draw(renderer, _modelViewTransform, flags); } director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); // FIX ME: Why need to set _orderOfArrival to 0?? // Please refer to https://github.com/cocos2d/cocos2d-x/pull/6920 // setOrderOfArrival(0); }
void GameScene_Box2D::draw(Renderer *renderer, const Mat4 &transform, uint32_t transformFlags) { Layer::draw(renderer, transform, transformFlags); Director* director = Director::getInstance(); GL::enableVertexAttribs(GL::VERTEX_ATTRIB_FLAG_POSITION ); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _world->DrawDebugData(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void ClippingNode::drawFullScreenQuadClearStencil() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); DrawPrimitives::drawSolidRect(Vec2(-1,-1), Vec2(1,1), Color4F(1, 1, 1, 1)); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void TestColliderDetector::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION ); Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); world->DrawDebugData(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void TestColliderDetector::onDraw(const Mat4 &transform, uint32_t flags) { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); armature2->drawContour(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void PhysicDelegate::onDraw(const Mat4 &transform, uint32_t flags) { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION ); _world->DrawDebugData(); CHECK_GL_ERROR_DEBUG(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void Node::visit(Renderer* renderer, const Mat4 &parentTransform, bool parentTransformUpdated) { // quick return if not visible. children won't be drawn. if (!_visible) { return; } bool dirty = _transformUpdated || parentTransformUpdated; if(dirty) _modelViewTransform = this->transform(parentTransform); _transformUpdated = false; // IMPORTANT: // To ease the migration to v3.0, we still support the Mat4 stack, // but it is deprecated and your code should not rely on it Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); int i = 0; if(!_children.empty()) { sortAllChildren(); // draw children zOrder < 0 for( ; i < _children.size(); i++ ) { auto node = _children.at(i); if ( node && node->_localZOrder < 0 ) node->visit(renderer, _modelViewTransform, dirty); else break; } // self draw this->draw(renderer, _modelViewTransform, dirty); for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, dirty); } else { this->draw(renderer, _modelViewTransform, dirty); } // reset for next frame _orderOfArrival = 0; director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void FPB2DebugDrawLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION ); Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _modelViewMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _customCommand.init(_globalZOrder); _customCommand.func = CC_CALLBACK_0(FPB2DebugDrawLayer::onDraw, this); renderer->addCommand(&_customCommand); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void StencilStateManager::drawFullScreenQuadClearStencil() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when setting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadIdentityMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); Vec2 vertices[] = { Vec2(-1.0f, -1.0f), Vec2(1.0f, -1.0f), Vec2(1.0f, 1.0f), Vec2(-1.0f, 1.0f) }; auto glProgram = GLProgramCache::getInstance()->getGLProgram(GLProgram::SHADER_NAME_POSITION_U_COLOR); int colorLocation = glProgram->getUniformLocation("u_color"); CHECK_GL_ERROR_DEBUG(); Color4F color(1, 1, 1, 1); glProgram->use(); glProgram->setUniformsForBuiltins(); glProgram->setUniformLocationWith4fv(colorLocation, (GLfloat*) &color.r, 1); glBindBuffer(GL_ARRAY_BUFFER, 0); GL::enableVertexAttribs( GL::VERTEX_ATTRIB_FLAG_POSITION ); glVertexAttribPointer(GLProgram::VERTEX_ATTRIB_POSITION, 2, GL_FLOAT, GL_FALSE, 0, vertices); glDrawArrays(GL_TRIANGLE_FAN, 0, 4); CC_INCREMENT_GL_DRAWN_BATCHES_AND_VERTICES(1, 4); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void HelloWorld::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { Layer::draw(renderer, transform, flags); Director* director = Director::getInstance(); // CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); GL::enableVertexAttribs( cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION ); //m_test->Step(&settings); mWorld->DrawDebugData(); CHECK_GL_ERROR_DEBUG(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void SkeletonRenderer::drawDebug (Renderer* renderer, const Mat4 &transform, uint32_t transformFlags) { Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); DrawNode* drawNode = DrawNode::create(); if (_debugSlots) { // Slots. // DrawPrimitives::setDrawColor4B(0, 0, 255, 255); glLineWidth(1); Vec2 points[4]; V3F_C4B_T2F_Quad quad; for (int i = 0, n = _skeleton->slotsCount; i < n; i++) { spSlot* slot = _skeleton->drawOrder[i]; if (!slot->attachment || slot->attachment->type != SP_ATTACHMENT_REGION) continue; spRegionAttachment* attachment = (spRegionAttachment*)slot->attachment; spRegionAttachment_computeWorldVertices(attachment, slot->bone, _worldVertices); points[0] = Vec2(_worldVertices[0], _worldVertices[1]); points[1] = Vec2(_worldVertices[2], _worldVertices[3]); points[2] = Vec2(_worldVertices[4], _worldVertices[5]); points[3] = Vec2(_worldVertices[6], _worldVertices[7]); drawNode->drawPoly(points, 4, true, Color4F::BLUE); } } if (_debugBones) { // Bone lengths. glLineWidth(2); for (int i = 0, n = _skeleton->bonesCount; i < n; i++) { spBone *bone = _skeleton->bones[i]; float x = bone->data->length * bone->a + bone->worldX; float y = bone->data->length * bone->c + bone->worldY; drawNode->drawLine(Vec2(bone->worldX, bone->worldY), Vec2(x, y), Color4F::RED); } // Bone origins. auto color = Color4F::BLUE; // Root bone is blue. for (int i = 0, n = _skeleton->bonesCount; i < n; i++) { spBone *bone = _skeleton->bones[i]; drawNode->drawPoint(Vec2(bone->worldX, bone->worldY), 4, color); if (i == 0) color = Color4F::GREEN; } } drawNode->draw(renderer, transform, transformFlags); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void Sprite3D::visit(cocos2d::Renderer *renderer, const cocos2d::Mat4 &parentTransform, uint32_t parentFlags) { // quick return if not visible. children won't be drawn. if (!_visible) { return; } uint32_t flags = processParentFlags(parentTransform, parentFlags); flags |= FLAGS_RENDER_AS_3D; // Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); bool visibleByCamera = isVisitableByVisitingCamera(); int i = 0; if(!_children.empty()) { sortAllChildren(); // draw children zOrder < 0 for( ; i < _children.size(); i++ ) { auto node = _children.at(i); if (node && node->getLocalZOrder() < 0) node->visit(renderer, _modelViewTransform, flags); else break; } // self draw if (visibleByCamera) this->draw(renderer, _modelViewTransform, flags); for(auto it=_children.cbegin()+i; it != _children.cend(); ++it) (*it)->visit(renderer, _modelViewTransform, flags); } else if (visibleByCamera) { this->draw(renderer, _modelViewTransform, flags); } director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void SudokuBox::onDraw(const Mat4& transform) { //if the grid has only one row/col, dont draw the grid, because the grid maybe make player be confused. if (m_stagedata.rows_per_grid <= 1 || m_stagedata.cols_per_grid <= 1) return; int rows = m_stagedata.grids_in_row; int cols = m_stagedata.grids_in_col; if (rows <= 0 || cols <= 0) return; Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); CHECK_GL_ERROR_DEBUG(); //draw the grid with difference colors. Color4B gridColors[] = { Color4B(0, 255, 255, 255), Color4B(255, 0, 255, 255) }; int linW = 3; glLineWidth(linW); Size size = getContentSize(); float width = size.width / cols; float height = size.height / rows; for (int i = 0; i < rows; i++) { for (int j = 0; j < cols; j++) { Color4B cl = gridColors[(j+(i%2))%2]; DrawPrimitives::setDrawColor4B(cl.r, cl.g, cl.b, cl.a); Vec2 vertices[] = { Vec2(width*j+linW, height*i+linW), Vec2(width*j+linW, height*(i+1)-linW), Vec2(width*(j+1)-linW, height*(i+1)-linW), Vec2(width*(j+1)-linW, height*i+linW) }; DrawPrimitives::drawPoly(vertices, 4, true); } } CHECK_GL_ERROR_DEBUG(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void StayingBlobSprite::onDraw(const cocos2d::Mat4 &transform, uint32_t transformFlags) { if(_bodies.size() == 0)return; Vec2 vertices[NUM_SEGMENTS]; Vec2 opos = this->getPosition(); for(int i = 0; i < _bodies.size(); i++) { b2PolygonShape *shape = (b2PolygonShape *) _bodies[i]->GetFixtureList()->GetShape(); b2Vec2 point; if(i < NUM_SEGMENTS / 4) point = _bodies[i]->GetWorldVector(shape->GetVertex(0)); else if(i < NUM_SEGMENTS * 2/4) point = _bodies[i]->GetWorldVector(shape->GetVertex(1)); else if(i < NUM_SEGMENTS * 3/4) point = _bodies[i]->GetWorldVector(shape->GetVertex(2)); else if(i < NUM_SEGMENTS) point = _bodies[i]->GetWorldVector(shape->GetVertex(3)); b2Vec2 pos = _bodies[i]->GetPosition(); vertices[i].x = (point.x + pos.x)*PTM_RATIO - opos.x; vertices[i].y = (point.y + pos.y)*PTM_RATIO - opos.y; } Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); //glLineWidth( 5.0f ); //ccDrawColor4F(1.f, 0.125f, 0.15625f, 1); // tiny side burns (...Guesss that one way to call it) // for(int i = 0; i < _bodies.size(); i++) { // Vec2 target = (center - vertices[i]) * nub_pos; // target += center; // DrawPrimitives::drawSolidCircle(vertices[i], nub_size, CC_DEGREES_TO_RADIANS(360), 30); // } // draw the body //DrawPrimitives::drawSolidPoly(vertices, NUM_SEGMENTS, blobColor); DrawPrimitives::drawSolidPoly(vertices, NUM_SEGMENTS, Color4F(1, 1, 1, 1)); _face->setPosition(this->getCenter() + Vec2(-30, -100)*_face->getScale()); updateEye(); CHECK_GL_ERROR_DEBUG(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void Debug::onDraw(const Mat4 &transform, bool transformUpdated) { // ÀûÓÃStack»º´æ Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); CHECK_GL_ERROR_DEBUG(); // »±ß¿ò DrawPrimitives::setDrawColor4B(255, 255, 255, 255); glLineWidth(4); Vec2 vertices[] = { Vec2(1, 1), Vec2(1, visibleSize.height - 1), Vec2(visibleSize.width - 1, visibleSize.height - 1), Vec2(visibleSize.width - 1, 1) }; DrawPrimitives::drawPoly(vertices, 4, true); CHECK_GL_ERROR_DEBUG(); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void GameLayer::draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) { // // IMPORTANT: // This is only for debug purposes // It is recommend to disable it // Layer::draw(renderer, transform, flags); GL::enableVertexAttribs(cocos2d::GL::VERTEX_ATTRIB_FLAG_POSITION); Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); _customCommand.init(1000); _customCommand.func = CC_CALLBACK_0(GameLayer::onDraw, this,transform); renderer->addCommand(&_customCommand); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }
void LabelAtlas::drawDebugData(const Mat4& transform, bool transformUpdated) { Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); auto size = getContentSize(); Vec2 vertices[4]= { Vec2::ZERO, Vec2(size.width, 0), Vec2(size.width, size.height), Vec2(0, size.height) }; DrawPrimitives::drawPoly(vertices, 4, true); director->popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); }