void GameLayer::onDraw(const Mat4 &transform) { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); auto oldMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); _world->DrawDebugData(); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMV); }
void RenderTexture::onBegin() { // Director *director = Director::getInstance(); _oldProjMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _projectionMatrix); _oldTransMatrix = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _transformMatrix); if(!_keepMatrix) { director->setProjection(director->getProjection()); const Size& texSize = _texture->getContentSizeInPixels(); // Calculate the adjustment ratios based on the old and new projections Size size = director->getWinSizeInPixels(); float widthRatio = size.width / texSize.width; float heightRatio = size.height / texSize.height; Mat4 orthoMatrix; Mat4::createOrthographicOffCenter((float)-1.0 / widthRatio, (float)1.0 / widthRatio, (float)-1.0 / heightRatio, (float)1.0 / heightRatio, -1, 1, &orthoMatrix); director->multiplyMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, orthoMatrix); } //calculate viewport { Rect viewport; viewport.size.width = _fullviewPort.size.width; viewport.size.height = _fullviewPort.size.height; float viewPortRectWidthRatio = float(viewport.size.width)/_fullRect.size.width; float viewPortRectHeightRatio = float(viewport.size.height)/_fullRect.size.height; viewport.origin.x = (_fullRect.origin.x - _rtTextureRect.origin.x) * viewPortRectWidthRatio; viewport.origin.y = (_fullRect.origin.y - _rtTextureRect.origin.y) * viewPortRectHeightRatio; //glViewport(_fullviewPort.origin.x, _fullviewPort.origin.y, (GLsizei)_fullviewPort.size.width, (GLsizei)_fullviewPort.size.height); glViewport(viewport.origin.x, viewport.origin.y, (GLsizei)viewport.size.width, (GLsizei)viewport.size.height); } // Adjust the orthographic projection and viewport glGetIntegerv(GL_FRAMEBUFFER_BINDING, &_oldFBO); glBindFramebuffer(GL_FRAMEBUFFER, _FBO); // TODO: move this to configration, so we don't check it every time /* Certain Qualcomm Andreno gpu's will retain data in memory after a frame buffer switch which corrupts the render to the texture. The solution is to clear the frame buffer before rendering to the texture. However, calling glClear has the unintended result of clearing the current texture. Create a temporary texture to overcome this. At the end of RenderTexture::begin(), switch the attached texture to the second one, call glClear, and then switch back to the original texture. This solution is unnecessary for other devices as they don't have the same issue with switching frame buffers. */ if (Configuration::getInstance()->checkForGLExtension("GL_QCOM")) { // -- bind a temporary texture so we can clear the render buffer without losing our texture glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _textureCopy->getName(), 0); CHECK_GL_ERROR_DEBUG(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, _texture->getName(), 0); } }
void FPB2DebugDrawLayer::onDraw() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); Mat4 oldMV; oldMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV); mB2World->DrawDebugData(); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMV); }
void GameLayer::onDraw() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); auto oldMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV); PhysicsWorldManager::getInstance()->draw(); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMV); }
void Box2DTest::onDraw() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); auto oldMV = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewMV); world->DrawDebugData(); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldMV); }
// 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); }
// 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 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 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 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); } }
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); }
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 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, 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 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 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 Sprite::drawDebugData() { Director* director = Director::getInstance(); CCASSERT(nullptr != director, "Director is null when seting matrix stack"); Matrix oldModelView; oldModelView = director->getMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform); // draw bounding box Vector2 vertices[4] = { Vector2( _quad.bl.vertices.x, _quad.bl.vertices.y ), Vector2( _quad.br.vertices.x, _quad.br.vertices.y ), Vector2( _quad.tr.vertices.x, _quad.tr.vertices.y ), Vector2( _quad.tl.vertices.x, _quad.tl.vertices.y ), }; DrawPrimitives::drawPoly(vertices, 4, true); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, oldModelView); }
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 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 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 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 RenderTexture::onEnd() { Director *director = Director::getInstance(); glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO); // restore viewport director->setViewport(); // director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _oldProjMatrix); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _oldTransMatrix); }
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 RenderTexture::onEnd() { Director *director = Director::getInstance(); glBindFramebuffer(GL_FRAMEBUFFER, _oldFBO); // restore viewport director->setViewport(); const auto& vp = Camera::getDefaultViewport(); glViewport(vp._left, vp._bottom, vp._width, vp._height); // director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _oldProjMatrix); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _oldTransMatrix); }
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 LineContainer::draw(Renderer *renderer, const Mat4& transform, uint32_t flags){ //super.draw Node::draw(renderer, transform, flags); //pre-render Director* director = Director::getInstance(); director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW); director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, transform); //Create commands _customEnergyBar.func = CC_CALLBACK_0(LineContainer::drawEnergyBar, this, transform, flags); _customPivotLine.func = CC_CALLBACK_0(LineContainer::drawPivotLine, this, transform, flags); //add to renderer renderer->addCommand(&_customEnergyBar); renderer->addCommand(&_customPivotLine); }
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); }