//! [6] QPainterPath BasicToolsPlugin::generateShape(const QString &shape, QWidget *parent) { QPainterPath path; if (shape == tr("Circle")) { path.addEllipse(0, 0, 50, 50); } else if (shape == tr("Star")) { path.moveTo(90, 50); for (int i = 1; i < 5; ++i) { path.lineTo(50 + 40 * cos(0.8 * i * Pi), 50 + 40 * sin(0.8 * i * Pi)); } path.closeSubpath(); } else if (shape == tr("Text...")) { QString text = QInputDialog::getText(parent, tr("Text Shape"), tr("Enter text:"), QLineEdit::Normal, tr("Qt")); if (!text.isEmpty()) { QFont timesFont("Times", 50); timesFont.setStyleStrategy(QFont::ForceOutline); path.addText(0, 0, timesFont, text); } } return path; }
osg::ref_ptr<osg::Node> createText() { osg::Geode* geode = new osg::Geode(); std::string timesFont("fonts/arial.ttf"); // turn lighting off for the text and disable depth test to ensure it's always ontop. osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); osg::Vec3 position(150.0f,200.0f,0.0f); osg::Vec3 delta(0.0f,-120.0f,0.0f); { osgText::Text* text = new osgText::Text; geode->addDrawable( text ); text->setFont(timesFont); text->setPosition(position); text->setText("Start your Leap Motion pointing at the screen!"); position += delta; } return geode; }
// TODO: 视点位置正确,中心位置和Up位置不正确 osg::Node* ESTCreateHUD::createPositionHUD( osgText::Text* updateText ) { osg::Camera* camera = initialCamera(); std::string timesFont("cour.ttf"); // 下面字幕的位置 osg::Vec3 position(10.0, 80.0, 0.0); osg::Geode* geode = new osg::Geode; osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING, osg::StateAttribute::OFF); stateset->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); geode->setName("The text label"); geode->addDrawable(updateText); camera->addChild(geode); updateText->setCharacterSize(20.0f); updateText->setFont(timesFont); updateText->setColor(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f)); updateText->setText(""); updateText->setPosition(position); updateText->setDataVariance(osg::Object::DYNAMIC); return camera; }
void HeightPoint::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *) { painter->setPen(Qt::NoPen); painter->setBrush(Qt::darkGray); painter->drawEllipse(-7, -7, 20, 20); QRadialGradient gradient(-3, -3, 10); if (option->state & QStyle::State_Sunken) { gradient.setCenter(3, 3); gradient.setFocalPoint(3, 3); gradient.setColorAt(1, QColor(Qt::yellow).light(120)); gradient.setColorAt(0, QColor(Qt::darkYellow).light(120)); } else { gradient.setColorAt(0, Qt::yellow); gradient.setColorAt(1, Qt::darkYellow); } painter->setBrush(gradient); painter->setPen(QPen(Qt::black, 0)); painter->drawEllipse(-10, -10, 20, 20); //draw id Number QPainterPath textPath; QFont timesFont("Times", 20); QString waypointid = QString("%1").arg(wp->getId()); timesFont.setStyleStrategy(QFont::ForceOutline); textPath.addText(8, -8, timesFont, waypointid); painter->drawPath(textPath); }
osg::Node* createHUD() { // add a string reporting the type of winding rule tessellation applied osg::Geode* geode = new osg::Geode(); std::string timesFont("fonts/arial.ttf"); // turn lighting off for the text and disable depth test to ensure its always ontop. osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); // Disable depth test, and make sure that the hud is drawn after everything // else so that it always appears ontop. stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); stateset->setRenderBinDetails(11,"RenderBin"); osg::Vec3 position(150.0f,900.0f,0.0f); osg::Vec3 delta(0.0f,-30.0f,0.0f); { osgText::Text* text = new osgText::Text; geode->addDrawable( text ); text->setFont(timesFont); text->setPosition(position); text->setText("Tessellation example - no tessellation (use 'W' wireframe to visualise)"); text->setColor(osg::Vec4(1.0,1.0,0.8,1.0)); position += delta; } { osgText::Text* text = new osgText::Text; geode->addDrawable( text ); text->setFont(timesFont); text->setPosition(position); text->setText("Press 'n' to use an alternative tessellation."); } // create the hud. osg::MatrixTransform* modelview_abs = new osg::MatrixTransform; modelview_abs->setReferenceFrame(osg::Transform::ABSOLUTE_RF); modelview_abs->setMatrix(osg::Matrix::identity()); modelview_abs->addChild(geode); osg::Projection* projection = new osg::Projection; projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); projection->addChild(modelview_abs); return projection; }
osg::Camera* createHUD(unsigned int w, unsigned int h) { // create a camera to set up the projection and model view matrices, and the subgraph to draw in the HUD osg::Camera* camera = new osg::Camera; // set the projection matrix camera->setProjectionMatrix(osg::Matrix::ortho2D(0,w,0,h)); // set the view matrix camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setViewMatrix(osg::Matrix::identity()); // only clear the depth buffer camera->setClearMask(GL_DEPTH_BUFFER_BIT); // draw subgraph after main camera view. camera->setRenderOrder(osg::Camera::POST_RENDER); // we don't want the camera to grab event focus from the viewers main camera(s). camera->setAllowEventFocus(false); // add to this camera a subgraph to render { osg::Geode* geode = new osg::Geode(); std::string timesFont("fonts/arial.ttf"); // turn lighting off for the text and disable depth test to ensure it's always ontop. osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); osg::Vec3 position(50.0f,h-50,0.0f); { osgText::Text* text = new osgText::Text; geode->addDrawable( text ); text->setFont(timesFont); text->setPosition(position); text->setText("A simple multi-touch-example\n1 touch = rotate, \n2 touches = drag + scale, \n3 touches = home"); } camera->addChild(geode); } return camera; }
InfoIndicator::InfoIndicator(int widgetWidth, int widgetHeight, QWidget *parent) : QWidget(parent), indWidth(widgetWidth), indHeight(widgetHeight), showAll(false) { setContextMenuPolicy(Qt::ActionsContextMenu); setToolTip(tr("Drag the info indicator with the left mouse button.\n" "Use the right mouse button to open the Settings and Profile Widgets.")); setWindowTitle(tr("Info Indicator")); setWindowOpacity(GUI_OPACITY); QPalette pal; pal.setColor(QPalette::Background, MIDAS_GREY); setAutoFillBackground(true); setPalette(pal); setWindowFlags(Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint); layout = new QHBoxLayout; //layout->setSpacing(WIDGET_BUFFER); layout->setMargin(0); setLayout(layout); QFont timesFont("Times", 9, QFont::Bold); stateLabel = new QLabel(); stateLabel->setFont(timesFont); button = new QPushButton("+", this); button->setText(getShowAllString()); button->setFixedWidth(widgetHeight - 4); // Modify this line if getShowAllString has more than just a single character button->setFixedHeight(widgetHeight - 4); QFont timesSmall("Times", 8, QFont::DemiBold); button->setFont(timesSmall); connect(button, SIGNAL(released()), this, SLOT(handleButton())); layout->addSpacerItem(new QSpacerItem(6, 6)); layout->addWidget(stateLabel, 1, Qt::AlignLeft); layout->addWidget(button, 0, Qt::AlignRight); layout->addSpacerItem(new QSpacerItem(2, 2)); setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); setMinimumSize(indWidth, indHeight); }
void SequenceDisplayer::registerSequenceImages(int seqId, QString sequenceName, std::vector<sequenceImageSet> sequenceImages) { sequenceData newSequence; newSequence.sequenceImages = sequenceImages; QFont timesFont("Times", 9, QFont::Bold); newSequence.seqLabel = new QLabel(tr("%1").arg(sequenceName)); newSequence.seqLabel->setWordWrap(true); formBoxLabel(newSequence.seqLabel); newSequence.seqLabel->setFont(timesFont); newSequence.seqLabel->setFixedSize(GRID_ELEMENT_SIZE * LABEL_NUM_COLS, GRID_ELEMENT_SIZE); newSequence.seqPosLabel = new QLabel; newSequence.seqPosLabel->setFont(timesFont); formBoxLabel(newSequence.seqPosLabel); std::vector<sequenceImageSet>::iterator it; for (it = newSequence.sequenceImages.begin(); it != newSequence.sequenceImages.end(); it++) { it->currentImgLabel = new QLabel; formBoxLabel(it->currentImgLabel); } sequenceIdToDataMap[seqId] = newSequence; }
osg::Node* createHUD() { // create the hud. derived from osgHud.cpp // adds a set of quads, each in a separate Geode - which can be picked individually // eg to be used as a menuing/help system! // Can pick texts too! osg::Camera* hudCamera = new osg::Camera; hudCamera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); hudCamera->setProjectionMatrixAsOrtho2D(0,1280,0,1024); hudCamera->setViewMatrix(osg::Matrix::identity()); hudCamera->setRenderOrder(osg::Camera::POST_RENDER); hudCamera->setClearMask(GL_DEPTH_BUFFER_BIT); std::string timesFont("fonts/times.ttf"); // turn lighting off for the text and disable depth test to ensure its always ontop. osg::Vec3 position(150.0f,800.0f,0.0f); osg::Vec3 delta(0.0f,-60.0f,0.0f); { osg::Geode* geode = new osg::Geode(); osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); geode->setName("simple"); hudCamera->addChild(geode); osgText::Text* text = new osgText::Text; geode->addDrawable( text ); text->setFont(timesFont); text->setText("Picking in Head Up Displays is simple!"); text->setPosition(position); position += delta; } for (int i=0; i<5; i++) { osg::Vec3 dy(0.0f,-30.0f,0.0f); osg::Vec3 dx(120.0f,0.0f,0.0f); osg::Geode* geode = new osg::Geode(); osg::StateSet* stateset = geode->getOrCreateStateSet(); const char *opts[]={"One", "Two", "Three", "January", "Feb", "2003"}; osg::Geometry *quad=new osg::Geometry; stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); std::string name="subOption"; name += " "; name += std::string(opts[i]); geode->setName(name); osg::Vec3Array* vertices = new osg::Vec3Array(4); // 1 quad osg::Vec4Array* colors = new osg::Vec4Array; colors = new osg::Vec4Array; colors->push_back(osg::Vec4(0.8-0.1*i,0.1*i,0.2*i, 1.0)); quad->setColorArray(colors, osg::Array::BIND_OVERALL); (*vertices)[0]=position; (*vertices)[1]=position+dx; (*vertices)[2]=position+dx+dy; (*vertices)[3]=position+dy; quad->setVertexArray(vertices); quad->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS,0,4)); geode->addDrawable(quad); hudCamera->addChild(geode); position += delta; } { // this displays what has been selected osg::Geode* geode = new osg::Geode(); osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); geode->setName("The text label"); hudCamera->addChild(geode); position += delta; } return hudCamera; }
//! [1] Window::Window() { QPainterPath rectPath; rectPath.moveTo(20.0, 30.0); rectPath.lineTo(80.0, 30.0); rectPath.lineTo(80.0, 70.0); rectPath.lineTo(20.0, 70.0); rectPath.closeSubpath(); //! [1] //! [2] QPainterPath roundRectPath; roundRectPath.moveTo(80.0, 35.0); roundRectPath.arcTo(70.0, 30.0, 10.0, 10.0, 0.0, 90.0); roundRectPath.lineTo(25.0, 30.0); roundRectPath.arcTo(20.0, 30.0, 10.0, 10.0, 90.0, 90.0); roundRectPath.lineTo(20.0, 65.0); roundRectPath.arcTo(20.0, 60.0, 10.0, 10.0, 180.0, 90.0); roundRectPath.lineTo(75.0, 70.0); roundRectPath.arcTo(70.0, 60.0, 10.0, 10.0, 270.0, 90.0); roundRectPath.closeSubpath(); //! [2] //! [3] QPainterPath ellipsePath; ellipsePath.moveTo(80.0, 50.0); ellipsePath.arcTo(20.0, 30.0, 60.0, 40.0, 0.0, 360.0); //! [3] //! [4] QPainterPath piePath; piePath.moveTo(50.0, 50.0); piePath.arcTo(20.0, 30.0, 60.0, 40.0, 60.0, 240.0); piePath.closeSubpath(); //! [4] //! [5] QPainterPath polygonPath; polygonPath.moveTo(10.0, 80.0); polygonPath.lineTo(20.0, 10.0); polygonPath.lineTo(80.0, 30.0); polygonPath.lineTo(90.0, 70.0); polygonPath.closeSubpath(); //! [5] //! [6] QPainterPath groupPath; groupPath.moveTo(60.0, 40.0); groupPath.arcTo(20.0, 20.0, 40.0, 40.0, 0.0, 360.0); groupPath.moveTo(40.0, 40.0); groupPath.lineTo(40.0, 80.0); groupPath.lineTo(80.0, 80.0); groupPath.lineTo(80.0, 40.0); groupPath.closeSubpath(); //! [6] //! [7] QPainterPath textPath; QFont timesFont("Times", 50); timesFont.setStyleStrategy(QFont::ForceOutline); textPath.addText(10, 70, timesFont, tr("Qt")); //! [7] //! [8] QPainterPath bezierPath; bezierPath.moveTo(20, 30); bezierPath.cubicTo(80, 0, 50, 50, 80, 80); //! [8] //! [9] QPainterPath starPath; starPath.moveTo(90, 50); for (int i = 1; i < 5; ++i) { starPath.lineTo(50 + 40 * cos(0.8 * i * Pi), 50 + 40 * sin(0.8 * i * Pi)); } starPath.closeSubpath(); //! [9] //! [10] #if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) renderAreas.push_back(new RenderArea(rectPath)); renderAreas.push_back(new RenderArea(roundRectPath)); renderAreas.push_back(new RenderArea(ellipsePath)); renderAreas.push_back(new RenderArea(piePath)); renderAreas.push_back(new RenderArea(polygonPath)); renderAreas.push_back(new RenderArea(groupPath)); #endif renderAreas.push_back(new RenderArea(textPath)); renderAreas.push_back(new RenderArea(bezierPath)); renderAreas.push_back(new RenderArea(starPath)); //! [10] //! [11] fillRuleComboBox = new QComboBox; fillRuleComboBox->addItem(tr("Odd Even"), Qt::OddEvenFill); fillRuleComboBox->addItem(tr("Winding"), Qt::WindingFill); fillRuleLabel = new QLabel(tr("Fill &Rule:")); fillRuleLabel->setBuddy(fillRuleComboBox); //! [11] //! [12] fillColor1ComboBox = new QComboBox; populateWithColors(fillColor1ComboBox); fillColor1ComboBox->setCurrentIndex( fillColor1ComboBox->findText("mediumslateblue")); fillColor2ComboBox = new QComboBox; populateWithColors(fillColor2ComboBox); fillColor2ComboBox->setCurrentIndex( fillColor2ComboBox->findText("cornsilk")); fillGradientLabel = new QLabel(tr("&Fill Gradient:")); fillGradientLabel->setBuddy(fillColor1ComboBox); fillToLabel = new QLabel(tr("to")); fillToLabel->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed); penWidthSpinBox = new QSpinBox; penWidthSpinBox->setRange(0, 20); penWidthLabel = new QLabel(tr("&Pen Width:")); penWidthLabel->setBuddy(penWidthSpinBox); penColorComboBox = new QComboBox; populateWithColors(penColorComboBox); penColorComboBox->setCurrentIndex( penColorComboBox->findText("darkslateblue")); penColorLabel = new QLabel(tr("Pen &Color:")); penColorLabel->setBuddy(penColorComboBox); rotationAngleSpinBox = new QSpinBox; rotationAngleSpinBox->setRange(0, 359); rotationAngleSpinBox->setWrapping(true); rotationAngleSpinBox->setSuffix("\xB0"); rotationAngleLabel = new QLabel(tr("&Rotation Angle:")); rotationAngleLabel->setBuddy(rotationAngleSpinBox); //! [12] //! [16] connect(fillRuleComboBox, SIGNAL(activated(int)), this, SLOT(fillRuleChanged())); connect(fillColor1ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); connect(fillColor2ComboBox, SIGNAL(activated(int)), this, SLOT(fillGradientChanged())); connect(penColorComboBox, SIGNAL(activated(int)), this, SLOT(penColorChanged())); for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++) { connect(penWidthSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setPenWidth(int))); connect(rotationAngleSpinBox, SIGNAL(valueChanged(int)), *it, SLOT(setRotationAngle(int))); } //! [16] //! [17] QGridLayout *topLayout = new QGridLayout; #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) topLayout->setSizeConstraint(QLayout::SetNoConstraint); #endif int i=0; for(QList<RenderArea*>::iterator it = renderAreas.begin(); it != renderAreas.end(); it++, i++) topLayout->addWidget(*it, i / 3, i % 3); QGridLayout *mainLayout = new QGridLayout; #if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR) mainLayout->setSizeConstraint(QLayout::SetNoConstraint); #endif mainLayout->addLayout(topLayout, 0, 0, 1, 4); mainLayout->addWidget(fillRuleLabel, 1, 0); mainLayout->addWidget(fillRuleComboBox, 1, 1, 1, 3); mainLayout->addWidget(fillGradientLabel, 2, 0); mainLayout->addWidget(fillColor1ComboBox, 2, 1); mainLayout->addWidget(fillToLabel, 2, 2); mainLayout->addWidget(fillColor2ComboBox, 2, 3); mainLayout->addWidget(penWidthLabel, 3, 0); mainLayout->addWidget(penWidthSpinBox, 3, 1, 1, 3); mainLayout->addWidget(penColorLabel, 4, 0); mainLayout->addWidget(penColorComboBox, 4, 1, 1, 3); #if !defined(Q_OS_SYMBIAN) && !defined(Q_WS_MAEMO_5) && !defined(Q_WS_SIMULATOR) mainLayout->addWidget(rotationAngleLabel, 5, 0); mainLayout->addWidget(rotationAngleSpinBox, 5, 1, 1, 3); #endif setLayout(mainLayout); //! [17] //! [18] fillRuleChanged(); fillGradientChanged(); penColorChanged(); penWidthSpinBox->setValue(2); setWindowTitle(tr("Painter Paths")); }
osg::Camera* createHUD() { // create a camera to set up the projection and model view matrices, and the subgraph to drawn in the HUD osg::Camera* camera = new osg::Camera; // set the projection matrix camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); // set the view matrix camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setViewMatrix(osg::Matrix::identity()); // only clear the depth buffer camera->setClearMask(GL_DEPTH_BUFFER_BIT); // draw subgraph after main camera view. camera->setRenderOrder(osg::Camera::POST_RENDER); // we don't want the camera to grab event focus from the viewers main camera(s). camera->setAllowEventFocus(false); // add to this camera a subgraph to render { osg::Geode* geode = new osg::Geode(); std::string timesFont("fonts/arial.ttf"); // turn lighting off for the text and disable depth test to ensure its always ontop. osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); osg::Vec3 position(150.0f,800.0f,0.0f); osg::Vec3 delta(0.0f,-120.0f,0.0f); { osgText::Text* text = new osgText::Text; geode->addDrawable( text ); text->setFont(timesFont); text->setPosition(position); text->setText("Head Up Displays are simple :-)"); position += delta; } { osgText::Text* text = new osgText::Text; geode->addDrawable( text ); text->setFont(timesFont); text->setPosition(position); text->setText("All you need to do is create your text in a subgraph."); position += delta; } { osgText::Text* text = new osgText::Text; geode->addDrawable( text ); text->setFont(timesFont); text->setPosition(position); text->setText("Then place an osg::Camera above the subgraph\n" "to create an orthographic projection.\n"); position += delta; } { osgText::Text* text = new osgText::Text; geode->addDrawable( text ); text->setFont(timesFont); text->setPosition(position); text->setText("Set the Camera's ReferenceFrame to ABSOLUTE_RF to ensure\n" "it remains independent from any external model view matrices."); position += delta; } { osgText::Text* text = new osgText::Text; geode->addDrawable( text ); text->setFont(timesFont); text->setPosition(position); text->setText("And set the Camera's clear mask to just clear the depth buffer."); position += delta; } { osgText::Text* text = new osgText::Text; geode->addDrawable( text ); text->setFont(timesFont); text->setPosition(position); text->setText("And finally set the Camera's RenderOrder to POST_RENDER\n" "to make sure its drawn last."); position += delta; } { osg::BoundingBox bb; for(unsigned int i=0;i<geode->getNumDrawables();++i) { bb.expandBy(geode->getDrawable(i)->getBound()); } osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array; float depth = bb.zMin()-0.1; vertices->push_back(osg::Vec3(bb.xMin(),bb.yMax(),depth)); vertices->push_back(osg::Vec3(bb.xMin(),bb.yMin(),depth)); vertices->push_back(osg::Vec3(bb.xMax(),bb.yMin(),depth)); vertices->push_back(osg::Vec3(bb.xMax(),bb.yMax(),depth)); geom->setVertexArray(vertices); osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,0.0f,1.0f)); geom->setNormalArray(normals); geom->setNormalBinding(osg::Geometry::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(1.0f,1.0,0.8f,0.2f)); geom->setColorArray(colors); geom->setColorBinding(osg::Geometry::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); osg::StateSet* stateset = geom->getOrCreateStateSet(); stateset->setMode(GL_BLEND,osg::StateAttribute::ON); //stateset->setAttribute(new osg::PolygonOffset(1.0f,1.0f),osg::StateAttribute::ON); stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); geode->addDrawable(geom); } camera->addChild(geode); } return camera; }
bool DePee::createHUD() { osg::Geode* geode = new osg::Geode(); std::string timesFont("fonts/arial.ttf"); // turn lighting off for the text and disable depth test to ensure its always ontop. osg::StateSet* stateset = geode->getOrCreateStateSet(); stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); stateset->setTextureAttributeAndModes(1, _normalDepthMap0.get(), osg::StateAttribute::OFF); stateset->setTextureAttributeAndModes(2, _normalDepthMap1.get(), osg::StateAttribute::OFF); stateset->setTextureAttributeAndModes(3, _edgeMap.get(), osg::StateAttribute::OFF); stateset->setTextureAttributeAndModes(4, _colorMap.get(), osg::StateAttribute::OFF); stateset->setTextureAttributeAndModes(5, _noiseMap.get(), osg::StateAttribute::OFF); osg::Vec3 position(5.0f,7.0f,0.0f); osg::Vec3 delta(0.0f,-120.0f,0.0f); _hudText = new osgText::Text; { geode->addDrawable( _hudText ); _hudText->setDataVariance(osg::Object::DYNAMIC); _hudText->setFont(timesFont); _hudText->setPosition(position); _hudText->setText("Head Up Display"); _hudText->setColor(osg::Vec4(0.5, 0.5, 0.5, 1.0)); _hudText->setCharacterSize(20.0); position += delta; } { osg::BoundingBox bb; for(unsigned int i=0; i<geode->getNumDrawables(); ++i) { bb.expandBy(geode->getDrawable(i)->getBoundingBox()); } osg::Geometry* geom = new osg::Geometry; osg::Vec3Array* vertices = new osg::Vec3Array; float depth = bb.zMin()-0.1; vertices->push_back(osg::Vec3(bb.xMin(),bb.yMax(),depth)); vertices->push_back(osg::Vec3(bb.xMin(),bb.yMin(),depth)); vertices->push_back(osg::Vec3(bb.xMax(),bb.yMin(),depth)); vertices->push_back(osg::Vec3(bb.xMax(),bb.yMax(),depth)); geom->setVertexArray(vertices); osg::Vec3Array* normals = new osg::Vec3Array; normals->push_back(osg::Vec3(0.0f,0.0f,1.0f)); geom->setNormalArray(normals, osg::Array::BIND_OVERALL); osg::Vec4Array* colors = new osg::Vec4Array; colors->push_back(osg::Vec4(0.0f,0.0,0.0f,0.3f)); geom->setColorArray(colors, osg::Array::BIND_OVERALL); geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS,0,4)); osg::StateSet* ss = geom->getOrCreateStateSet(); ss->setMode(GL_BLEND,osg::StateAttribute::ON); ss->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); //geode->addDrawable(geom); } osg::Camera* camera = new osg::Camera; // set the projection matrix camera->setProjectionMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); // set the view matrix camera->setReferenceFrame(osg::Transform::ABSOLUTE_RF); camera->setViewMatrix(osg::Matrix::identity()); // only clear the depth buffer camera->setClearMask(GL_DEPTH_BUFFER_BIT); // draw subgraph after main camera view. camera->setRenderOrder(osg::Camera::POST_RENDER); camera->addChild(geode); _parent->addChild(camera); return true; }
void test_handling_text(GC_TYPE &gc) { char unicodeString[] = {230, 234, 223, 220, 0}; // Text handling test. Make sure timesi.ttf is in the current directory! kiva::font_type timesFont("times", 12, "regular"); kiva::font_type copperFont("coprgtl", 12, "regular"); kiva::font_type curlzFont("arial", 12, "regular"); //kiva::font_type unicodeFont("uni_font", 12, "regular"); gc.set_alpha(1.0); gc.set_text_drawing_mode(kiva::TEXT_FILL); gc.set_font(timesFont); //gc.set_font(unicodeFont); gc.translate_ctm(100.0, 100.0); gc.move_to(-5,0); gc.line_to(5,0); gc.move_to(0,5); gc.line_to(0,-5); gc.move_to(0,0); gc.stroke_path(); //agg24::trans_affine_translation txtTrans(200.0,150.0); agg24::trans_affine_rotation txtRot(agg24::deg2rad(30)); //txtTrans.premultiply(txtRot); //txtTrans *= txtRot; gc.set_text_matrix(txtRot); //gc.set_text_position(150.5, 350.5); //kiva::rect_type bbox(gc.get_text_extent("Hello")); //gc.get_text_matrix().transform(&bbox.x, &bbox.y); gc.show_text("Hello"); gc.show_text("foobar"); gc.show_text(unicodeString); //txtRot.invert(); //gc.set_text_matrix(txtRot); //gc.show_text("inverted"); // gc.rect(bbox); // gc.stroke_path(); /* gc.set_font(copperFont); gc.set_text_position(150.5, 250.5); kiva::rect_type bbox2(gc.get_text_extent("Hello")); gc.get_text_matrix().transform(&bbox2.x, &bbox2.y); gc.show_text("Hello"); // gc.rect(bbox2); // gc.stroke_path(); gc.set_font(curlzFont); gc.set_text_position(150.5, 150.5); kiva::rect_type bbox3(gc.get_text_extent("Hello")); gc.get_text_matrix().transform(&bbox3.x, &bbox3.y); gc.show_text("Hello"); // gc.rect(bbox3); // gc.stroke_path(); */ //gc.set_stroke_color(red); //gc.show_text("blah"); //gc.set_text_position(200.0, 100.0); //gc.show_text("Hello"); //gc.show_text_translate("Hello", 10.0, 360.0); //gc.set_font_size(36); //gc.show_text_translate("Hello", 10.0, 190.0); }