- Timestamp:
- 10/28/05 10:35:55 (8 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgshaderterrain/osgshaderterrain.cpp
r4600 r4627 5 5 #include <osg/Geode> 6 6 #include <osg/Geometry> 7 #include <osg/GL2Extensions> 7 8 #include <osg/Material> 8 9 #include <osg/Math> 9 10 #include <osg/MatrixTransform> 10 11 #include <osg/PolygonOffset> 12 #include <osg/Program> 11 13 #include <osg/Projection> 14 #include <osg/Shader> 12 15 #include <osg/ShapeDrawable> 13 16 #include <osg/StateSet> 14 17 #include <osg/Switch> 15 18 #include <osg/Texture2D> 19 #include <osg/Uniform> 16 20 17 21 #include <osgDB/ReadFile> … … 506 510 for(r=0;r<numRows;++r) 507 511 { 508 for(c=0;c<numColumns;++c)509 {510 min_z = osg::minimum(min_z,vertex[r+c*numRows][2]);511 max_z = osg::maximum(max_z,vertex[r+c*numRows][2]);512 }512 for(c=0;c<numColumns;++c) 513 { 514 min_z = osg::minimum(min_z,vertex[r+c*numRows][2]); 515 max_z = osg::maximum(max_z,vertex[r+c*numRows][2]); 516 } 513 517 } 514 518 … … 520 524 for(r=0;r<numRows;++r) 521 525 { 522 for(c=0;c<numColumns;++c)523 {524 *((float*)(terrainImage->data(c,r))) = (vertex[r+c*numRows][2]-min_z)*scale_z;525 }526 for(c=0;c<numColumns;++c) 527 { 528 *((float*)(terrainImage->data(c,r))) = (vertex[r+c*numRows][2]-min_z)*scale_z; 529 } 526 530 } 527 531 … … 537 541 if (image) 538 542 { 539 osg::Texture2D* texture = new osg::Texture2D;540 541 texture->setImage(image);542 stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON);543 osg::Texture2D* texture = new osg::Texture2D; 544 545 texture->setImage(image); 546 stateset->setTextureAttributeAndModes(1,texture,osg::StateAttribute::ON); 543 547 } 544 548 … … 630 634 pos.x() = origin.x(); 631 635 tex.x() = 0.0f; 632 for(c=0;c<numColumns;++c)633 {634 v[vi].set(pos.x(),pos.y(),pos.z());636 for(c=0;c<numColumns;++c) 637 { 638 v[vi].set(pos.x(),pos.y(),pos.z()); 635 639 pos.x()+=columnCoordDelta; 636 640 tex.x()+=columnTexDelta; 637 641 ++vi; 638 }642 } 639 643 pos.y() += rowCoordDelta; 640 644 tex.y() += rowTexDelta; … … 650 654 geometry->addPrimitiveSet(&drawElements); 651 655 int ei=0; 652 for(c=0;c<numColumns;++c)653 {654 drawElements[ei++] = (r+1)*numColumns+c;655 drawElements[ei++] = (r)*numColumns+c;656 }656 for(c=0;c<numColumns;++c) 657 { 658 drawElements[ei++] = (r+1)*numColumns+c; 659 drawElements[ei++] = (r)*numColumns+c; 660 } 657 661 } 658 662 … … 775 779 viewer.realize(); 776 780 781 // not all hardware can support vertex texturing, so check first. 782 for(unsigned int contextID = 0; 783 contextID<viewer.getDisplaySettings()->getMaxNumberOfGraphicsContexts(); 784 ++contextID) 785 { 786 osg::GL2Extensions* gl2ext = osg::GL2Extensions::Get(contextID,false); 787 if( gl2ext ) 788 { 789 if( !gl2ext->isGlslSupported() ) 790 { 791 std::cout<<"ERROR: GLSL not supported by OpenGL driver."<<std::endl; 792 return 1; 793 } 794 795 GLint numVertexTexUnits = 0; 796 glGetIntegerv( GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &numVertexTexUnits ); 797 if( numVertexTexUnits <= 0 ) 798 { 799 std::cout<<"ERROR: vertex texturing not supported by OpenGL driver."<<std::endl; 800 return 1; 801 } 802 } 803 } 804 777 805 while( !viewer.done() ) 778 806 {
