Changeset 4321 for OpenSceneGraph/trunk/examples/osgmovie/osgmovie.cpp
- Timestamp:
- 06/08/05 17:57:05 (8 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgmovie/osgmovie.cpp
r4087 r4321 179 179 180 180 181 osg::Geometry* createTexturedQuadGeometry(const osg::Vec3& pos,float width,float height, osg::Image* image) 182 { 183 bool useTextureRectangle = true; 181 osg::Geometry* createTexturedQuadGeometry(const osg::Vec3& pos,float width,float height, osg::Image* image, bool useTextureRectangle) 182 { 184 183 if (useTextureRectangle) 185 184 { … … 188 187 osg::Vec3(0.0f,0.0f,height), 189 188 0.0f,image->t(), image->s(),0.0f); 190 189 191 190 pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0, 192 191 new osg::TextureRectangle(image), … … 200 199 osg::Vec3(width,0.0f,0.0f), 201 200 osg::Vec3(0.0f,0.0f,height), 202 0.0f,0.0f, 1.0f,1.0f); 201 0.0f,1.0f, 1.0f,0.0f); 202 203 osg::Texture2D* texture = new osg::Texture2D(image); 204 texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); 203 205 204 206 pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0, 205 new osg::Texture2D(image),207 texture, 206 208 osg::StateAttribute::ON); 207 209 … … 221 223 arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); 222 224 225 bool useTextureRectangle = true; 226 bool useShader = false; 223 227 224 228 // construct the viewer. 225 229 osgProducer::Viewer viewer(arguments); 230 231 while (arguments.read("--texture2D")) useTextureRectangle=false; 232 while (arguments.read("--shader")) useShader=true; 226 233 227 234 // set up the value with sensible default event handlers. … … 245 252 osg::ref_ptr<osg::Geode> geode = new osg::Geode; 246 253 osg::Vec3 pos(0.0f,0.0f,0.0f); 247 254 255 osg::StateSet* stateset = geode->getOrCreateStateSet(); 256 stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 257 258 if (useShader) 259 { 260 //useTextureRectangle = false; 261 262 static const char *shaderSource = { 263 "uniform vec4 cutoff_color;\n" 264 "uniform samplerRect movie_texture;" 265 "void main(void)\n" 266 "{\n" 267 " vec4 texture_color = textureRect(movie_texture, gl_TexCoord[0]); \n" 268 " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" 269 " gl_FragColor = texture_color;\n" 270 "}\n" 271 }; 272 osg::Program* program = new osg::Program; 273 program->addShader(new osg::Shader(osg::Shader::FRAGMENT,shaderSource)); 274 275 stateset->addUniform(new osg::Uniform("cutoff_color",osg::Vec4(0.1f,0.1f,0.1f,1.0f))); 276 stateset->addUniform(new osg::Uniform("movie_texture",0)); 277 278 stateset->setAttribute(program); 279 280 } 281 282 248 283 for(int i=1;i<arguments.argc();++i) 249 284 { … … 256 291 if (image) 257 292 { 258 geode->addDrawable(createTexturedQuadGeometry(pos,image->s(),image->t(),image)); 259 geode->getOrCreateStateSet()->setMode(GL_LIGHTING,osg::StateAttribute::OFF); 260 293 geode->addDrawable(createTexturedQuadGeometry(pos,image->s(),image->t(),image, useTextureRectangle)); 294 261 295 pos.z() += image->t()*1.5f; 262 296 }
