MYGUIManager::MYGUIManager() : _gui(0), _platform(0), _resourcePathFile("resources.xml"), _resourceCoreFile("MyGUI_Core.xml"), _activeContextID(0), _initialized(false), _gw(0), _uiScale(1.0f), _useHWCursor(true) { setSupportsDisplayList( false ); getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); getOrCreateStateSet()->setMode( GL_DEPTH_TEST, osg::StateAttribute::OFF ); }
//============================================================================== BoxShapeGeode::BoxShapeGeode(dart::dynamics::BoxShape* shape, EntityNode* parent, BoxShapeNode* parentNode) : ShapeNode(parentNode->getShape(), parent, this), mBoxShape(shape), mDrawable(nullptr) { getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON); getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); extractData(); }
//============================================================================== LineSegmentShapeGeode::LineSegmentShapeGeode( std::shared_ptr<dart::dynamics::LineSegmentShape> shape, EntityNode* parent) : ShapeNode(shape, parent, this), mLineSegmentShape(shape), mDrawable(nullptr), mLineWidth(new osg::LineWidth) { getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON); getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF); extractData(true); }
/*Set color of sphere*/ void SphereShape::setShapeColor(osg::Vec4 color) { setColor(color); _color = color; if(color[3] != 1.0) getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); else getOrCreateStateSet()->setRenderingHint(osg::StateSet::DEFAULT_BIN); }
osg::Camera* createHUD(osg::Image* bgImage) { // 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, 1.0f, 1.0f, 0)); // 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::NESTED_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(); // 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); { auto texturedQuad = osg::createTexturedQuadGeometry( osg::Vec3(0.f, 0.f, 0.f), osg::Vec3(1.0f, 0.f, 0.f), osg::Vec3(0.f, 1.0f, 0.f), bgImage->s(), bgImage->t()); auto textureRect = new osg::TextureRectangle(bgImage); textureRect->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); textureRect->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); textureRect->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); texturedQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0, textureRect, osg::StateAttribute::ON); texturedQuad->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF); geode->addDrawable(texturedQuad); } camera->addChild(geode); } return camera; }
void CircleShape::setColor(osg::Vec4 c0, osg::Vec4 c1) { (*_colors)[0].set(c0[0], c0[1], c0[2], c0[3]); for(int i = 1; i < (int)_colors->size(); i++) { (*_colors)[i].set(c1[0], c1[1], c1[2], c1[3]); } if( (c0[3] != 1.0) || (c1[3] != 1.0)) getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); else getOrCreateStateSet()->setRenderingHint(osg::StateSet::DEFAULT_BIN); }
HeightmapShapeGeode<S>::HeightmapShapeGeode( dynamics::HeightmapShape<S>* shape, ShapeFrameNode* parentShapeFrame, HeightmapShapeNode<S>* parentNode) : ShapeNode(parentNode->getShape(), parentShapeFrame, this), mParentNode(parentNode), mHeightmapShape(shape), mDrawable(nullptr) { getOrCreateStateSet()->setMode(GL_BLEND, ::osg::StateAttribute::ON); getOrCreateStateSet()->setMode(GL_LIGHTING, ::osg::StateAttribute::ON); getOrCreateStateSet()->setAttributeAndModes( new ::osg::CullFace(::osg::CullFace::BACK)); extractData(); }
/*Constructor for Sphere*/ SphereShape::SphereShape(std::string command, std::string name) { _type = SimpleShape::SPHERE; BasicShape::setName(name); //create sphere and add to geode as shape drawable _sphere = new osg::Sphere(); setShape(_sphere); setPosition(osg::Vec3(0.0, 0.0, 0.0), 1.0); setShapeColor(osg::Vec4(1.0, 1.0, 1.0, 1.0)); update(command); osg::StateSet* state = getOrCreateStateSet(); state -> setMode(GL_BLEND, osg::StateAttribute::ON); osg::Material* mat = new osg::Material(); mat -> setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); state -> setAttributeAndModes(mat, osg::StateAttribute::ON); setShaders("", ""); }
ChunkLodDrawable::ChunkLodDrawable() { setSupportsDisplayList(false); _tree = NULL; osg::Timer t; _last_tick = t.tick(); _triangle_count = 0; _lastBoundIndex = -1; osg::StateSet *ss = getOrCreateStateSet(); osg::CullFace *cull = new osg::CullFace(); cull->setMode(osg::CullFace::BACK); ss->setAttributeAndModes(cull); osg::TexGen *texgen = new osg::TexGen(); texgen->setMode(osg::TexGen::OBJECT_LINEAR); ss->setTextureAttributeAndModes(0, texgen); // ss->setMode(GL_LIGHTING,osg::StateAttribute::OFF); //_details = new RegisterCombinerDetails; _details = new MultiTextureARBDetails; _details->addDetail("detail_texture.png", 3125); _details->addDetail("detail5.png", 625); _details->addDetail("detail4.png", 125); _details->init(ss); // TODO delete _details in dtor }
CircleShape::CircleShape(std::string command, std::string name) { _type = SimpleShape::CIRCLE; BasicShape::setName(name); _numFaces = 20; _vertices = new osg::Vec3Array(_numFaces + 2); _colors = new osg::Vec4Array(_numFaces + 2); setPosition(osg::Vec3(0.0, 0.0, 0.0), 1.0); setColor(osg::Vec4(1.0, 0.0, 0.0, 1.0),osg::Vec4(0.0, 1.0, 0.0, 1.0)); update(command); setVertexArray(_vertices); setColorArray(_colors); setColorBinding(osg::Geometry::BIND_PER_VERTEX); addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::TRIANGLE_FAN,0,_numFaces + 2)); osg::StateSet* state = getOrCreateStateSet(); state->setMode(GL_BLEND, osg::StateAttribute::ON); state->setMode(GL_LIGHTING, osg::StateAttribute::OFF); //osg::Material* mat = new osg::Material(); //mat->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE); //state->setAttributeAndModes(mat, osg::StateAttribute::ON); }
bool Widget::setTexture(osg::Texture* texture, bool setTexCoords, bool useTextRect) { if(!texture) return false; getOrCreateStateSet()->setTextureAttributeAndModes( 0, texture, osg::StateAttribute::ON ); if(setTexCoords) { if(useTextRect) { osg::Image* image = texture->getImage(0); setTexCoord(0.0f, 0.0f, LOWER_LEFT); setTexCoord(image->s(), 0.0f, LOWER_RIGHT); setTexCoord(image->s(), image->t(), UPPER_RIGHT); setTexCoord(0.0f, image->t(), UPPER_LEFT); } else { setTexCoord(0.0f, 0.0f, LOWER_LEFT); setTexCoord(1.0f, 0.0f, LOWER_RIGHT); setTexCoord(1.0f, 1.0f, UPPER_RIGHT); setTexCoord(0.0f, 1.0f, UPPER_LEFT); } } return true; }
// set clouds texture bool CloudsLayer::setCloudsTexture( av::weather_params::cloud_type cl_type ) { static const std::array<std::string const, av::weather_params::clouds_types_num> tex_names = { "images/sky/clouds_none.dds", "images/sky/clouds_cloudy.dds", "images/sky/clouds_cirrus.dds", "images/sky/clouds_overcast.dds" }; if (_clType != cl_type) { _clType = cl_type; //FIXME TODO загрузка один раз osg::StateSet * sset = getOrCreateStateSet(); osg::ref_ptr<osg::Texture2D> cloudsTex = new osg::Texture2D; cloudsTex->setImage( osgDB::readImageFile(tex_names[cl_type],new osgDB::Options("")) ); cloudsTex->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR_MIPMAP_LINEAR); cloudsTex->setMaxAnisotropy(16.0f); cloudsTex->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT ); cloudsTex->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT ); cloudsTex->setWrap( osg::Texture::WRAP_R, osg::Texture::REPEAT ); osg::StateAttribute::GLModeValue value = osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE | osg::StateAttribute::PROTECTED; sset->setTextureAttributeAndModes( 0, cloudsTex.get(), value ); return true; } return false; }
SilverLiningNode::SilverLiningNode( const char* licenseUser, const char* licenseKey ) : _initialized(false) { _sky = new SkyDrawable(this); _sky->setUseVertexBufferObjects( false ); _sky->setUseDisplayList( false ); _sky->getOrCreateStateSet()->setRenderBinDetails( 98, "RenderBin" ); _sky->getOrCreateStateSet()->setAttributeAndModes( new osg::Depth(osg::Depth::LEQUAL, 0.0, 1.0, false) ); addDrawable( _sky.get() ); _cloud = new CloudDrawable(this); _cloud->setUseVertexBufferObjects( false ); _cloud->setUseDisplayList( false ); _cloud->getOrCreateStateSet()->setRenderBinDetails( 99, "RenderBin" ); _cloud->setCullCallback( new AlwaysKeepCallback ); // This seems to avoid cloud to twinkle sometimes addDrawable( _cloud.get() ); AtmosphereUpdater* updater = new AtmosphereUpdater; setUpdateCallback( updater ); setCullCallback( updater ); setCullingActive( false ); getOrCreateStateSet()->setRenderBinDetails( 100, "RenderBin" ); _atmosphere = new SilverLining::Atmosphere( licenseUser, licenseKey ); _atmosphere->DisableFarCulling( true ); _atmosphere->EnableLensFlare( true ); const char* slPath = getenv( "SILVERLINING_PATH" ); if ( slPath ) _resourcePath = osgDB::convertFileNameToNativeStyle(std::string(slPath) + "/resources/"); }
void ChunkLodDrawable::setChunkLodTree(ChunkLodTree* tree) { _tree = tree; if (tree != NULL) { osg::StateSet *ss = getOrCreateStateSet(); tree->apply(ss); } }
StarsGeode::StarsGeode(const char* brightStarsFilePath) : osg::Geode() , m_program(new osg::Program) , m_vShader(new osg::Shader(osg::Shader::VERTEX)) , m_gShader(new osg::Shader(osg::Shader::GEOMETRY)) , m_fShader(new osg::Shader(osg::Shader::FRAGMENT)) , u_R(NULL) , u_q(NULL) , u_noise1(NULL) , u_color(NULL) , u_glareIntensity(NULL) , u_glareScale(NULL) , u_apparentMagnitude(NULL) , u_scattering(NULL) , u_scintillations(NULL) , u_scale(NULL) { setName("Stars"); osg::StateSet* stateSet = getOrCreateStateSet(); setupNode(stateSet, brightStarsFilePath); setupUniforms(stateSet); setupShader(stateSet); setupTextures(stateSet); };
//============================================================================== BoxShapeGeode::BoxShapeGeode( const std::shared_ptr<dart::dynamics::BoxShape>& shape, ShapeFrameNode* parentShapeFrame) : ShapeNode(shape, parentShapeFrame, this), mBoxShape(shape), mDrawable(nullptr) { getOrCreateStateSet()->setMode(GL_BLEND, ::osg::StateAttribute::ON); extractData(); }
//============================================================================== CylinderShapeGeode::CylinderShapeGeode(dart::dynamics::CylinderShape* shape, EntityNode* parentEntity, CylinderShapeNode* parentNode) : ShapeNode(parentNode->getShape(), parentEntity, this), mCylinderShape(shape), mDrawable(nullptr) { getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON); extractData(); }
LaserScanLine::LaserScanLine(URGCPPWrapper &urg) : urg(urg), vertices(new osg::Vec3Array(urg.getNumberOfPoints())), color(new osg::Vec4Array(1)) { setDataVariance(osg::Object::DYNAMIC); getOrCreateStateSet()->setAttribute(new osg::Point(3), osg::StateAttribute::ON); addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, urg.getNumberOfPoints())); setColorBinding(osg::Geometry::BIND_OVERALL); (*color)[0] = osg::Vec4(1.0f, 0.0f, 0.0f, 1.0f); setColorArray(color); }
//============================================================================== EllipsoidShapeGeode::EllipsoidShapeGeode(dart::dynamics::EllipsoidShape* shape, ShapeFrameNode* parentShapeFrame, EllipsoidShapeNode* parentNode) : ShapeNode(parentNode->getShape(), parentShapeFrame, this), mParentNode(parentNode), mEllipsoidShape(shape), mDrawable(nullptr) { getOrCreateStateSet()->setMode(GL_BLEND, ::osg::StateAttribute::ON); extractData(); }
//------------------------------------------------------------------------------ void UnitInMipmapOut::init() { // default initialization UnitInOut::init(); // if we have to create mipmaps for an input texture if (mGenerateMipmapInputIndex >= 0) { setOutputTexture(getInputTexture(mGenerateMipmapInputIndex)); assignOutputTexture(); } // enable mipmap levels in the output texture enableMipmapGeneration(); // if generating of mipmaps done in software, then generate drawables if (mUseShader) { // disable standard fbo //getOrCreateStateSet()->removeAttribute(mFBO.get()); getOrCreateStateSet()->removeAttribute(mViewport.get()); // this is the base level of mipmap generation // if the output texture is the same as input texture, then // we do not need to recompute the level 0, because it should // stay the same. int baseLevel = (mGenerateMipmapInputIndex < 0 ? 0 : 1); // attach a drawable for each mipmap level for (int i = baseLevel; i < mNumLevels; i++) { // setup the drawable osg::Drawable* draw = mMipmapDrawable[i]; osg::StateSet* ss = draw->getOrCreateStateSet(); // setup drawable uniforms osg::Uniform* w = ss->getOrCreateUniform(OSGPPU_VIEWPORT_WIDTH_UNIFORM, osg::Uniform::FLOAT); osg::Uniform* h = ss->getOrCreateUniform(OSGPPU_VIEWPORT_HEIGHT_UNIFORM, osg::Uniform::FLOAT); w->set((float)mMipmapViewport[i]->width()); h->set((float)mMipmapViewport[i]->height()); osg::Uniform* iw = ss->getOrCreateUniform(OSGPPU_VIEWPORT_INV_WIDTH_UNIFORM, osg::Uniform::FLOAT); osg::Uniform* ih = ss->getOrCreateUniform(OSGPPU_VIEWPORT_INV_HEIGHT_UNIFORM, osg::Uniform::FLOAT); iw->set(1.0f / (float)mMipmapViewport[i]->width()); ih->set(1.0f / (float)mMipmapViewport[i]->height()); osg::Uniform* ln = ss->getOrCreateUniform(OSGPPU_MIPMAP_LEVEL_NUM_UNIFORM, osg::Uniform::FLOAT); ln->set((float)mNumLevels); osg::Uniform* le = ss->getOrCreateUniform(OSGPPU_MIPMAP_LEVEL_UNIFORM, osg::Uniform::FLOAT); le->set((float)i); } } }
SkyBox::SkyBox() { setReferenceFrame( osg::Transform::ABSOLUTE_RF ); setCullingActive( false ); osg::StateSet* ss = getOrCreateStateSet(); ss->setAttributeAndModes( new osg::Depth(osg::Depth::LEQUAL, 1.0f, 1.0f) ); ss->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); ss->setMode( GL_CULL_FACE, osg::StateAttribute::OFF ); ss->setRenderBinDetails( 5, "RenderBin" ); }
void setPlane (const osg::Plane& plane) { if (plane == mPlane) return; mPlane = plane; mClipNode->getClipPlaneList().clear(); mClipNode->addClipPlane(new osg::ClipPlane(0, osg::Plane(mPlane.getNormal(), 0))); // mPlane.d() applied in FlipCallback mClipNode->setStateSetModes(*getOrCreateStateSet(), osg::StateAttribute::ON); mClipNode->setCullingActive(false); }
DisplayTexture::DisplayTexture() { setReferenceFrame(osg::Transform::ABSOLUTE_RF); setRenderOrder(osg::Camera::POST_RENDER); setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); setViewMatrix(osg::Matrix()); setProjectionMatrix(osg::Matrix::ortho2D(0, 1, 0, 1)); getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF); addChild(createFullscreenQuad()); setName("Display"); }
void TextShape::update() { OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); if( !_dirty ) return; osg::Vec3 p = getPosition(); osg::Vec4 c = getColor(); osg::Vec4 bc = getBackdropColor(); float size = getCharacterHeight(); std::string text = getText().createUTF8EncodedString(); p = getParameter("pos")->asVec3Type()->getValue(); c = getParameter("color")->asVec4Type()->getValue(); bc = getParameter("bcolor")->asVec4Type()->getValue(); size = getParameter("size")->asFloatType()->getValue(); text = getParameter("label")->asStringType()->getValue(); bool enableOutline = getParameter("enableOutline")->asBoolType()->getValue(); // TODO background color // TODO not sure if want to make it so the font gets added all the time hmmm //setFont(font); // check if outline should be enabled if( enableOutline ) { setBackdropType(osgText::Text::OUTLINE); setColor(c); setBackdropColor(bc); } else { setBackdropType(osgText::Text::NONE); setColor(c); } setText(text); setCharacterSize(size); setPosition(p); dirtyBound(); //if(c[3] != 1.0) getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); //else // getOrCreateStateSet()->setRenderingHint(osg::StateSet::DEFAULT_BIN); // reset flag _dirty = false; }
/*set Shaders for Sphere*/ void SphereShape::setShaders(std::string vert_file, std::string frag_file) { if(vert_file.compare(_vertex_shader) == 0 && frag_file.compare(_fragment_shader) == 0) return; osg::StateSet* state = getOrCreateStateSet(); osg::Program* prog = new osg::Program(); osg::Shader* vert = new osg::Shader(osg::Shader::VERTEX); osg::Shader* frag = new osg::Shader(osg::Shader::FRAGMENT); _vertex_shader = vert_file; _fragment_shader = frag_file; //try to load shader files std::string file_path = cvr::ConfigManager::getEntry("dir", "Plugin.Mugic.Shader", ""); if(!_vertex_shader.empty()) { bool loaded = vert->loadShaderSourceFromFile(file_path + _vertex_shader); if(!loaded) { std::cout << "could not load vertex shader." << std::endl; _vertex_shader = ""; } else { prog->addShader(vert); } } if(!_fragment_shader.empty()) { bool loaded = frag->loadShaderSourceFromFile(file_path + _fragment_shader); if(!loaded) { std::cout << "could not load fragment shader." << std::endl; _fragment_shader = ""; } else { prog->addShader(frag); } } state->setAttributeAndModes(prog, osg::StateAttribute::ON); }
FlexDrawable::FlexDrawable() : _solver(NULL) { setUseDisplayList( false ); setUseVertexBufferObjects( false ); setCullCallback( FlexUpdater::instance() ); osg::ref_ptr<osg::Program> program = new osg::Program; program->addShader( new osg::Shader(osg::Shader::VERTEX, flexVertCode) ); program->addShader( new osg::Shader(osg::Shader::FRAGMENT, flexFragCode) ); osg::StateSet* ss = getOrCreateStateSet(); ss->setAttributeAndModes( program.get() ); }
Refraction() { unsigned int rttSize = Settings::Manager::getInt("rtt size", "Water"); setRenderOrder(osg::Camera::PRE_RENDER); setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); setRenderTargetImplementation(osg::Camera::FRAME_BUFFER_OBJECT); setReferenceFrame(osg::Camera::RELATIVE_RF); setSmallFeatureCullingPixelSize(Settings::Manager::getInt("small feature culling pixel size", "Water")); setName("RefractionCamera"); setCullMask(Mask_Effect|Mask_Scene|Mask_Terrain|Mask_Actor|Mask_ParticleSystem|Mask_Sky|Mask_Sun|Mask_Player|Mask_Lighting); setNodeMask(Mask_RenderToTexture); setViewport(0, 0, rttSize, rttSize); // No need for Update traversal since the scene is already updated as part of the main scene graph // A double update would mess with the light collection (in addition to being plain redundant) setUpdateCallback(new NoTraverseCallback); // No need for fog here, we are already applying fog on the water surface itself as well as underwater fog // assign large value to effectively turn off fog // shaders don't respect glDisable(GL_FOG) osg::ref_ptr<osg::Fog> fog (new osg::Fog); fog->setStart(10000000); fog->setEnd(10000000); getOrCreateStateSet()->setAttributeAndModes(fog, osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE); mClipCullNode = new ClipCullNode; addChild(mClipCullNode); mRefractionTexture = new osg::Texture2D; mRefractionTexture->setTextureSize(rttSize, rttSize); mRefractionTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); mRefractionTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); mRefractionTexture->setInternalFormat(GL_RGB); mRefractionTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); mRefractionTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); attach(osg::Camera::COLOR_BUFFER, mRefractionTexture); mRefractionDepthTexture = new osg::Texture2D; mRefractionDepthTexture->setSourceFormat(GL_DEPTH_COMPONENT); mRefractionDepthTexture->setInternalFormat(GL_DEPTH_COMPONENT24); mRefractionDepthTexture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); mRefractionDepthTexture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); mRefractionDepthTexture->setSourceType(GL_UNSIGNED_INT); mRefractionDepthTexture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR); mRefractionDepthTexture->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR); attach(osg::Camera::DEPTH_BUFFER, mRefractionDepthTexture); }
void TextShape::update() { OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex); if( !_dirty ) return; osg::Vec3 p = getPosition(); osg::Vec4 c = getColor(); float size = getCharacterHeight(); std::string text = getText().createUTF8EncodedString(); setParameter("x", p.x()); setParameter("y", p.y()); setParameter("z", p.z()); setParameter("r", c.r()); setParameter("g", c.g()); setParameter("b", c.b()); setParameter("a", c.a()); setParameter("size", size); setParameter("label", text); setText(text); setCharacterSize(size); setPosition(p); setColor(c); dirtyBound(); if(c[3] != 1.0) getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); else getOrCreateStateSet()->setRenderingHint(osg::StateSet::DEFAULT_BIN); // reset flag _dirty = false; }
TexturePlaneNode::TexturePlaneNode() : _center( 0, 0, 0 ) , _width( 1, 1, 0 ) , _textureBrickSize( 64 ) , _needsUpdate( true ) , _disperseFactor( 0 ) , _useShaders( true ) , _swapTextureAxes( false ) { osg::ref_ptr<osg::LightModel> lightModel = new osg::LightModel; lightModel->setTwoSided( true ); getOrCreateStateSet()->setAttributeAndModes( lightModel.get() ); setNumChildrenRequiringUpdateTraversal( 1 ); }
void CSulShadow::init() { // create a texture using the boundingbox of the render target object m_rST = new CSulShadowTexture( m_rCasters, this ); m_rST->setShadowMapBounds( m_rShadowMapBounds ); m_rST->setTextureSize( m_size_squared ); m_rST->setLight( m_posLight ); m_rST->init(); m_rSceneRoot->addChild( m_rST->getNode() ); osg::StateSet* ss = getOrCreateStateSet(); ss->setTextureAttributeAndModes( UNIT, m_rST->getTexture(), osg::StateAttribute::ON | osg::StateAttribute::PROTECTED | osg::StateAttribute::OVERRIDE ); ss->setTextureMode( UNIT, GL_TEXTURE_GEN_S, osg::StateAttribute::ON | osg::StateAttribute::PROTECTED | osg::StateAttribute::OVERRIDE ); ss->setTextureMode( UNIT, GL_TEXTURE_GEN_T, osg::StateAttribute::ON | osg::StateAttribute::PROTECTED | osg::StateAttribute::OVERRIDE ); ss->setTextureMode( UNIT, GL_TEXTURE_GEN_R, osg::StateAttribute::ON | osg::StateAttribute::PROTECTED | osg::StateAttribute::OVERRIDE ); ss->setTextureMode( UNIT, GL_TEXTURE_GEN_Q, osg::StateAttribute::ON | osg::StateAttribute::PROTECTED | osg::StateAttribute::OVERRIDE ); // some shader stuff /* osg::Shader* fragment_shader = 0; osg::Shader* vert = 0; if ( m_fileShaderFrag.empty() ) { fragment_shader = new osg::Shader( osg::Shader::FRAGMENT, fragmentShaderSource_noBaseTexture ); } else { fragment_shader = new osg::Shader( osg::Shader::FRAGMENT ); fragment_shader->loadShaderSourceFromFile( m_fileShaderFrag ); } if ( !m_fileShaderVert.empty() ) { vert = new osg::Shader( osg::Shader::VERTEX ); vert->loadShaderSourceFromFile( m_fileShaderVert ); } osg::Program* program = new osg::Program; program->addShader( fragment_shader ); if ( vert ) { program->addShader( vert ); } ss->setAttribute( program ); */ osg::Uniform* shadowTextureSampler = new osg::Uniform("osgShadow_shadowTexture",(int)3); ss->addUniform( shadowTextureSampler ); }