本文整理汇总了C++中osg::StateSet类的典型用法代码示例。如果您正苦于以下问题:C++ StateSet类的具体用法?C++ StateSet怎么用?C++ StateSet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StateSet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
示例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);
}
}
}
示例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;
}
示例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);
}
}
}
示例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");
}
示例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);
}
示例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);
}
示例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 );
}
示例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());
}
示例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());
}
示例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 );
}
示例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());
}
}
示例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)));
}
}
}
示例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);
}
示例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);
};