Changeset 4429 for OpenSceneGraph/trunk/examples/osgforest/osgforest.cpp
- Timestamp:
- 08/09/05 11:11:15 (8 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgforest/osgforest.cpp
r4395 r4429 16 16 17 17 #include <osgDB/ReadFile> 18 #include <osgDB/FileUtils> 18 19 19 20 #include <osgUtil/IntersectVisitor> … … 776 777 ++itr) 777 778 { 778 #if 0779 779 glColor4fv(itr->ptr()); 780 _geometry->drawImplementation(state); 781 #else 782 glPushMatrix(); 783 glTranslatef((*itr)[0], (*itr)[1], (*itr)[2]); 784 glScalef( (*itr)[3],(*itr)[3],(*itr)[3] ); 785 _geometry->drawImplementation(state); 786 glPopMatrix(); 787 #endif 780 _geometry->draw(state); 788 781 } 789 782 } … … 967 960 968 961 _techniqueSwitch = new osg::Switch; 969 962 970 963 { 971 964 std::cout<<"Creating billboard based forest..."; … … 994 987 std::cout<<"done."<<std::endl; 995 988 } 996 989 997 990 { 998 991 osg::Group* group = new osg::Group; … … 1005 998 1006 999 { 1000 osg::Program* program = new osg::Program; 1001 stateset->setAttribute(program); 1002 1003 #if 1 1004 // use inline shaders 1005 1007 1006 /////////////////////////////////////////////////////////////////// 1008 1007 // vertex shader using just Vec4 coefficients 1009 1008 char vertexShaderSource[] = 1010 "void main(void) \n" 1011 "{ \n" 1009 "varying vec2 texcoord;\n" 1012 1010 "\n" 1013 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n" 1011 "void main(void)\n" 1012 "{\n" 1013 " vec3 position = gl_Vertex.xyz * gl_Color.w + gl_Color.xyz;\n" 1014 " gl_Position = gl_ModelViewProjectionMatrix * vec4(position,1.0);\n" 1015 " gl_FrontColor = vec4(1.0,1.0,1.0,1.0);\n" 1016 " texcoord = gl_MultiTexCoord0.st;\n" 1014 1017 "}\n"; 1015 1018 … … 1019 1022 char fragmentShaderSource[] = 1020 1023 "uniform sampler2D baseTexture; \n" 1024 "varying vec2 texcoord; \n" 1021 1025 "\n" 1022 1026 "void main(void) \n" 1023 1027 "{ \n" 1024 " gl_FragColor = texture2D( baseTexture, gl_TexCoord[0].xy); \n"1028 " gl_FragColor = texture2D( baseTexture, texcoord); \n" 1025 1029 "}\n"; 1026 1030 1027 1028 osg::Program* program = new osg::Program; 1029 stateset->setAttribute(program); 1030 1031 //osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX, vertexShaderSource); 1032 //program->addShader(vertex_shader); 1031 osg::Shader* vertex_shader = new osg::Shader(osg::Shader::VERTEX, vertexShaderSource); 1032 program->addShader(vertex_shader); 1033 1033 1034 1034 osg::Shader* fragment_shader = new osg::Shader(osg::Shader::FRAGMENT, fragmentShaderSource); 1035 1035 program->addShader(fragment_shader); 1036 1037 #else 1038 1039 // get shaders from source 1040 program->addShader(osg::Shader::readShaderFile(osg::Shader::VERTEX, osgDB::findDataFile("shaders/forest.vert"))); 1041 program->addShader(osg::Shader::readShaderFile(osg::Shader::FRAGMENT, osgDB::findDataFile("shaders/forest.frag"))); 1042 1043 #endif 1036 1044 1037 1045 osg::Uniform* baseTextureSampler = new osg::Uniform("baseTexture",0);
