• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ osg::StateSet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中osg::StateSet的典型用法代码示例。如果您正苦于以下问题:C++ StateSet类的具体用法?C++ StateSet怎么用?C++ StateSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了StateSet类的16个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: createTextureCubeMap

	void test::createTextureCubeMap(osg::StateSet& ss)
	{
		osg::ref_ptr<osg::TextureCubeMap> texture=new osg::TextureCubeMap;
		texture->setImage(osg::TextureCubeMap::POSITIVE_X,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/posx.jpg")));
		texture->setImage(osg::TextureCubeMap::NEGATIVE_X,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/negx.jpg")));
		texture->setImage(osg::TextureCubeMap::POSITIVE_Y,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/posy.jpg")));
		texture->setImage(osg::TextureCubeMap::NEGATIVE_Y,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/negy.jpg")));
		texture->setImage(osg::TextureCubeMap::POSITIVE_Z,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/posz.jpg")));
		texture->setImage(osg::TextureCubeMap::NEGATIVE_Z,
			osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Cubemap_snow/negz.jpg")));
		texture->setWrap(osg::Texture::WRAP_S,
			osg::Texture::CLAMP_TO_EDGE);
		texture->setWrap(osg::Texture::WRAP_T,
			osg::Texture::CLAMP_TO_EDGE);
		texture->setWrap(osg::Texture::WRAP_R,
			osg::Texture::CLAMP_TO_EDGE);
		texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
		texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
		ss.setTextureAttributeAndModes(0,texture.get());
		ss.setTextureAttributeAndModes(0,new osg::TexGen);
	}
开发者ID:gisair,项目名称:EAView,代码行数:26,代码来源:test.cpp


示例2: apply

    void apply(osg::StateSet& stateset)
    {
        if (_modAlphaFunc)
        {
            osg::AlphaFunc* alphaFunc = dynamic_cast<osg::AlphaFunc*>(stateset.getAttribute(osg::StateAttribute::ALPHAFUNC));
            if (alphaFunc)
            {
                OSG_INFO<<"Adjusting alpha func"<<std::endl;

                float alpha = alphaFunc->getReferenceValue();
                alpha = osg::clampBetween((1.0f-_currentY)*0.5f,0.0f,1.0f);

                alphaFunc->setReferenceValue(alpha);
            }
        }

        if (_modMaterial)
        {
            osg::Material* material = dynamic_cast<osg::Material*>(stateset.getAttribute(osg::StateAttribute::MATERIAL));
            if (material)
            {
                OSG_INFO<<"Adjusting material func"<<std::endl;
                float alpha = osg::clampBetween((_currentY+1.0f)*0.5f,0.0f,1.0f);
                material->setAlpha(osg::Material::FRONT_AND_BACK,alpha);
            }
        }
    }
开发者ID:BriacB,项目名称:osg,代码行数:27,代码来源:SlideEventHandler.cpp


示例3: backFaceCullingWithoutNormals

std::string GLSLUtils::backFaceCullingWithoutNormals( osg::StateSet &sset )
{
    std::string glsl_code;

    bool opposite = false;
    osg::StateAttribute *sa = sset.getAttribute( osg::StateAttribute::CULLFACE );
    if ( sa ) {
        osg::CullFace *cf = dynamic_cast<osg::CullFace*>(sa);
        if ( cf ) {
            // If culling front facing polygons, we consider it the opposite direction
            opposite = cf->getMode() == osg::CullFace::FRONT;
        }
    }

    // Check if the StateSet has backface culling enabled 
    // and add code to the shader to perform it 
    if ( sset.getMode(GL_CULL_FACE) == osg::StateAttribute::ON ) {
        if ( opposite ) {
            glsl_code += 
"    if ( gl_FrontFacing )\n"
"        discard;\n";
        }
        else {
            glsl_code += 
"    if ( !gl_FrontFacing )\n"
"        discard;\n";
        }
    }

	return glsl_code;
}
开发者ID:rpavlik,项目名称:maya2osg,代码行数:31,代码来源:glslutils.cpp


示例4: apply

 virtual void apply(osg::StateSet& stateset)
 {
     // search for the existence of any texture object attributes
     for(unsigned int i=0;i<stateset.getTextureAttributeList().size();++i)
     {
         osg::Texture* texture = dynamic_cast<osg::Texture*>(stateset.getTextureAttribute(i,osg::StateAttribute::TEXTURE));
         if (texture)
         {
             _textureSet.insert(texture);
         }
     }
 }
开发者ID:3dcl,项目名称:osg,代码行数:12,代码来源:osgconv.cpp


示例5: handle

void SimpleDotVisitor::handle(osg::StateSet &stateset, int id)
{
    std::stringstream label;

    label << "<top> " << stateset.className();
    if (!stateset.getName().empty())
    {
        label << "| " << stateset.getName();
    }

    drawNode(id, "Mrecord", "solid", label.str(), "green", "white");
}
开发者ID:hyyh619,项目名称:OpenSceneGraph-3.4.0,代码行数:12,代码来源:SimpleDotVisitor.cpp


示例6: AttachToRenderState

   void ShaderParamTextureCubeMap::AttachToRenderState(osg::StateSet &stateSet)
   {
      dtCore::RefPtr<osg::TextureCubeMap> texCube;

      if (GetTexture().empty() && GetTextureSourceType() != ShaderParamTexture::TextureSourceType::AUTO)
      {
         throw dtUtil::Exception(ShaderParameterException::INVALID_ATTRIBUTE,"Cannot attach to render state.  Texture "
            "for parameter " + GetName() + " has not been specified.", __FILE__, __LINE__);
      }

      osg::Uniform *uniform = NULL;

      if (IsShared())
         uniform = GetUniformParam();
      // Create a new one if unshared or if shared but not set yet
      if (uniform == NULL)
      {
         uniform = new osg::Uniform(osg::Uniform::SAMPLER_CUBE,GetName());
         uniform->set((int)GetTextureUnit());
         SetUniformParam(*uniform);
      }

      stateSet.addUniform(uniform);

      // Load (if necessary) and Set the Tex cube map on the StateSet
      if(GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_POSITIVE_X ||
         GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_NEGATIVE_X ||
         GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_POSITIVE_Y ||
         GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_NEGATIVE_Y ||
         GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_POSITIVE_Z ||
         GetTextureSourceType() == ShaderParamTexture::TextureSourceType::CUBEMAP_IMAGE_NEGATIVE_Z
      )
      {
         texCube = static_cast<osg::TextureCubeMap*>(GetTextureObject());

         // load or reload the image - allows caching from the template
         // Note - ImageSourceDirty may not be relevant anymore cause it now loads the image when you call SetTexture().
         // note - If shared, load only happens the first time it is assigned.
         // check only if face 0 exists. Is this sufficient?
         if (texCube->getImage(osg::TextureCubeMap::POSITIVE_X) == NULL || IsImageSourceDirty())
         {
            LoadImage();
            ApplyTextureCubeMapValues();
         }

         //Assign the completed texture attribute to the render state.
         stateSet.setTextureAttributeAndModes(GetTextureUnit(), texCube.get(), osg::StateAttribute::ON);
      }

      SetDirty(false);
   }
开发者ID:VRAC-WATCH,项目名称:deltajug,代码行数:51,代码来源:shaderparamtexturecubemap.cpp


示例7: Configurar_Material

void Configurar_Material()
{
		// version which sets the color of the wireframe.
	    material->setColorMode(osg::Material::OFF); // switch glColor usage off
	    // turn all lighting off
		material->setShininess(osg::Material::FRONT_AND_BACK,10.0f);
	    material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,1.0f,0.0f,1.0f));
	    material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,1.0f,0.0f,1.0f));
	    material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,1.0f,0.0f,1.0f));
	    // except emission... in which we set the color we desire
	    material->setEmission(osg::Material::FRONT_AND_BACK, osg::Vec4(0.0,0.0f,0.0f,1.0f));
	    stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
	    stateset->setMode(GL_LIGHTING,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON);
		Torreta->setStateSet(stateset);
}
开发者ID:gayoxo,项目名称:ProyectoIGr,代码行数:15,代码来源:Torreta.cpp


示例8: setBlending

void myModel::setBlending()
{
    _blendFunc = new osg::BlendFunc;
    _stateset = _model->getOrCreateStateSet();
    _blendFunc->setFunction(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    _stateset->setAttributeAndModes( _blendFunc );
}
开发者ID:wow2006,项目名称:OSG_Book,代码行数:7,代码来源:myProject03.cpp


示例9: createShaders

	void createShaders(osg::StateSet& ss)
	{
		osg::ref_ptr<osg::Shader> verShader=
			new osg::Shader(osg::Shader::VERTEX,vertSource);
		osg::ref_ptr<osg::Shader> fragShader=
			new osg::Shader(osg::Shader::FRAGMENT,fragSource);

		osg::ref_ptr<osg::Program> program=new osg::Program;
		program->addShader(verShader.get());
		program->addShader(fragShader.get());

		osg::ref_ptr<osg::Uniform> mainColor=
			new osg::Uniform("mainColor",osg::Vec4(1,0.5,0.5,1));
		mainColor->setUpdateCallback(new ColorCallback);

		ss.addUniform(mainColor.get());
		ss.setAttributeAndModes(program.get());
	}
开发者ID:gisair,项目名称:EAView,代码行数:18,代码来源:test.cpp


示例10:

	void test::createTexture2D(osg::StateSet& ss)
	{
		osg::ref_ptr<osg::Texture2D> texture=new osg::Texture2D;
		texture->setImage(osgDB::readImageFile(std::string(OSGFilePath)+std::string("/Images/clockface.jpg")));
		texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
		texture->setFilter(osg::Texture::MAG_FILTER,osg::Texture::LINEAR);
		texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_BORDER);
		texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_BORDER);
		texture->setBorderColor(osg::Vec4(1,1,0,1));
		ss.setTextureAttributeAndModes(0,texture.get());
	}
开发者ID:gisair,项目名称:EAView,代码行数:11,代码来源:test.cpp


示例11: createTexture2D

void createTexture2D( osg::StateSet& ss, bool useCustomizedData )
{
    osg::ref_ptr<osg::Texture2D> texture = new osg::Texture2D;
    if ( useCustomizedData ) texture->setImage( createCustomMipmap(32) );
    else texture->setImage( createInternalMipmap(32) );
    
    texture->setFilter( osg::Texture::MIN_FILTER, osg::Texture::LINEAR_MIPMAP_LINEAR );
    texture->setFilter( osg::Texture::MAG_FILTER, osg::Texture::LINEAR );
    texture->setWrap( osg::Texture::WRAP_S, osg::Texture::REPEAT );
    texture->setWrap( osg::Texture::WRAP_T, osg::Texture::REPEAT );
    ss.setTextureAttributeAndModes( 0, texture.get(), osg::StateAttribute::ON );
}
开发者ID:seafengl,项目名称:osgenginebook,代码行数:12,代码来源:mipmaps.cpp


示例12: apply

void GLObjectsVisitor::apply(osg::StateSet& stateset)
{
    if (_stateSetAppliedSet.count(&stateset)!=0) return;

    _stateSetAppliedSet.insert(&stateset);

    if (_mode & COMPILE_STATE_ATTRIBUTES && _renderInfo.getState())
    {
        stateset.compileGLObjects(*_renderInfo.getState());

        osg::Program* program = dynamic_cast<osg::Program*>(stateset.getAttribute(osg::StateAttribute::PROGRAM));
        if (program) {
            if( program->isFixedFunction() )
                _lastCompiledProgram = NULL; // It does not make sense to apply uniforms on fixed pipe
            else
                _lastCompiledProgram = program;
        }

        if (_lastCompiledProgram.valid() && !stateset.getUniformList().empty())
        {
            osg::Program::PerContextProgram* pcp = _lastCompiledProgram->getPCP(*_renderInfo.getState());
            if (pcp)
            {
                pcp->useProgram();

                _renderInfo.getState()->setLastAppliedProgramObject(pcp);

                const osg::StateSet::UniformList& ul = stateset.getUniformList();
                for(osg::StateSet::UniformList::const_iterator itr = ul.begin();
                    itr != ul.end();
                    ++itr)
                {
                    pcp->apply(*(itr->second.first));
                }
            }
        }
        else if(_renderInfo.getState()->getLastAppliedProgramObject())
        {
            osg::State* state = _renderInfo.getState();
            osg::GLExtensions* extensions = state->get<osg::GLExtensions>();
            extensions->glUseProgram(0);
            _renderInfo.getState()->setLastAppliedProgramObject(0);
        }

    }

    if (_mode & RELEASE_STATE_ATTRIBUTES)
    {
        stateset.releaseGLObjects(_renderInfo.getState());
    }

    if (_mode & CHECK_BLACK_LISTED_MODES)
    {
        stateset.checkValidityOfAssociatedModes(*_renderInfo.getState());
    }
}
开发者ID:bsmr-opengl,项目名称:OpenSceneGraph,代码行数:56,代码来源:GLObjectsVisitor.cpp


示例13: apply

        void apply(osg::StateSet& stateset)
        {
             if (_visited.count(&stateset)!=0) return;
            _visited.insert(&stateset);

            return;

            osg::notify(osg::NOTICE)<<"Found stateset "<<&stateset<<std::endl;
            osg::Program* program = dynamic_cast<osg::Program*>(stateset.getAttribute(osg::StateAttribute::PROGRAM));
            if (program)
            {
                osg::notify(osg::NOTICE)<<"   Found Program "<<program<<std::endl;
                for(unsigned int i=0; i<program->getNumShaders(); ++i)
                {
                    apply(*program, *(program->getShader(i)));
                }

            }
       }
开发者ID:3dcl,项目名称:osg,代码行数:19,代码来源:osgvertexattributes.cpp


示例14: DetachFromRenderState

   void ShaderParamTextureCubeMap::DetachFromRenderState(osg::StateSet &stateSet)
   {
      osg::TextureCubeMap *texCube = static_cast<osg::TextureCubeMap*>(GetTextureObject());
      if (texCube != NULL)
      {
         if (!IsShared())
         {
            osg::Image *image = new osg::Image();
            texCube->setImage(osg::TextureCubeMap::POSITIVE_X, image);
            texCube->setImage(osg::TextureCubeMap::NEGATIVE_X, image);
            texCube->setImage(osg::TextureCubeMap::POSITIVE_Y, image);
            texCube->setImage(osg::TextureCubeMap::NEGATIVE_Y, image);
            texCube->setImage(osg::TextureCubeMap::POSITIVE_Z, image);
            texCube->setImage(osg::TextureCubeMap::NEGATIVE_Z, image);

         }
         stateSet.setTextureAttributeAndModes(GetTextureUnit(),texCube,osg::StateAttribute::OFF);
      }

      // do normal parameter cleanup
      ShaderParameter::DetachFromRenderState(stateSet);
   }
开发者ID:VRAC-WATCH,项目名称:deltajug,代码行数:22,代码来源:shaderparamtexturecubemap.cpp


示例15: torreta

	torreta(int x, int y, int z,int tamaño)
	{
	Torreta = new osg::Group();
		material = new osg::Material;
		stateset =new osg::StateSet;
	//Configurar_Material();
	boton=y;
	left=x;
	//top=(8*tamaño)+z;
	//right=(11*tamaño);
	int	tamaño_cubo_grade=tamaño*5;
	nave* cubomio=new nave (x,y,z,tamaño_cubo_grade);
	int puntopunta=tamaño_cubo_grade;
	puntopunta=puntopunta/2;
	puntopunta=puntopunta-(tamaño/2);
	nave* cubomio2=new nave(x+puntopunta,y,tamaño_cubo_grade+z,tamaño);
	Torreta->addChild(cubomio->getNave());
	Torreta->addChild(cubomio2->getNave());
	top=tamaño_cubo_grade+tamaño+y;
	right=tamaño_cubo_grade+x;
	yDisparo=top;
	xDisparo=x+puntopunta;
		 stateset->setAttributeAndModes(material,osg::StateAttribute::OVERRIDE|osg::StateAttribute::OFF);
	};
开发者ID:gayoxo,项目名称:ProyectoIGr,代码行数:24,代码来源:Torreta.cpp


示例16: isTransparent

    virtual bool isTransparent(osg::StateSet& stateset)
    {
        bool hasTranslucentTexture = false;
        bool hasBlendFunc = dynamic_cast<osg::BlendFunc*>(stateset.getAttribute(osg::StateAttribute::BLENDFUNC))!=0;
        bool hasTransparentRenderingHint = stateset.getRenderingHint()==osg::StateSet::TRANSPARENT_BIN;
        bool hasDepthSortBin = (stateset.getRenderBinMode()==osg::StateSet::USE_RENDERBIN_DETAILS)?(stateset.getBinName()=="DepthSortedBin"):false;
        bool hasTexture = false;


        // search for the existence of any texture object attributes
        for(unsigned int i=0;i<stateset.getTextureAttributeList().size();++i)
        {
            osg::Texture* texture = dynamic_cast<osg::Texture*>(stateset.getTextureAttribute(i,osg::StateAttribute::TEXTURE));
            if (texture)
            {
                hasTexture = true;
                for (unsigned int im=0;im<texture->getNumImages();++im)
                {
                    osg::Image* image = texture->getImage(im);
                    if (image && image->isImageTranslucent()) hasTranslucentTexture = true;
                }
            }
        }

        if (hasTranslucentTexture || hasBlendFunc || hasTransparentRenderingHint || hasDepthSortBin)
        {
            ++_numTransparent;

            bool makeNonTransparent = false;

            switch(_mode)
            {
            case(MAKE_OPAQUE_TEXTURE_STATESET_OPAQUE):
                if (hasTexture && !hasTranslucentTexture)
                {
                    makeNonTransparent = true;
                }
                break;
            case(MAKE_ALL_STATESET_OPAQUE):
                makeNonTransparent = true;
                break;
            default:
                makeNonTransparent = false;
                break;
            }

            if (makeNonTransparent)
            {
                stateset.removeAttribute(osg::StateAttribute::BLENDFUNC);
                stateset.removeMode(GL_BLEND);
                stateset.setRenderingHint(osg::StateSet::DEFAULT_BIN);
                ++_numTransparentMadeOpaque;
            }


            return true;
        }
        else
        {
            ++_numOpaque;
            return false;
        }
    }
开发者ID:3dcl,项目名称:osg,代码行数:63,代码来源:osgconv.cpp



注:本文中的osg::StateSet类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ osg::Timer类代码示例发布时间:2022-05-31
下一篇:
C++ osg::State类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap