- bump_mapping = SGIsOpenGLExtensionSupported("GL_ARB_multitexture") &&
- SGIsOpenGLExtensionSupported("GL_ARB_texture_cube_map") &&
- SGIsOpenGLExtensionSupported("GL_ARB_texture_env_combine") &&
- SGIsOpenGLExtensionSupported("GL_ARB_texture_env_dot3") &&
- SGIsOpenGLExtensionSupported("GL_ARB_imaging");
-
- if ( bump_mapping ) {
- glGetIntegerv( GL_MAX_TEXTURE_UNITS_ARB, &nb_texture_unit );
- if ( nb_texture_unit < 2 ) {
- bump_mapping = false;
- }
- nb_texture_unit = 2; // Force the number of units for now
- }
-
- if ( bump_mapping ) {
-
- // This bump mapping code was inspired by the tutorial available at
- // http://www.paulsprojects.net/tutorials/simplebump/simplebump.html
- // and a NVidia white paper
- // http://developer.nvidia.com/object/bumpmappingwithregistercombiners.html
- // The normal map textures were generated by the normal map Gimp plugin :
- // http://nifelheim.dyndns.org/~cocidius/normalmap/
- //
- SGPath cloud_path;
-
- glActiveTexturePtr = (glActiveTextureProc)SGLookupFunction("glActiveTextureARB");
- glClientActiveTexturePtr = (glClientActiveTextureProc)SGLookupFunction("glClientActiveTextureARB");
- glBlendColorPtr = (glBlendColorProc)SGLookupFunction("glBlendColor");
-
- cloud_path.set(texture_path.str());
- cloud_path.append("overcast.rgb");
- color_map[ SG_CLOUD_OVERCAST ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
- color_map[ SG_CLOUD_OVERCAST ][ 0 ]->ref();
- cloud_path.set(texture_path.str());
- cloud_path.append("overcast_n.rgb");
- normal_map[ SG_CLOUD_OVERCAST ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
- normal_map[ SG_CLOUD_OVERCAST ][ 0 ]->ref();
-
- cloud_path.set(texture_path.str());
- cloud_path.append("overcast_top.rgb");
- color_map[ SG_CLOUD_OVERCAST ][ 1 ] = new ssgTexture( cloud_path.str().c_str() );
- color_map[ SG_CLOUD_OVERCAST ][ 1 ]->ref();
- cloud_path.set(texture_path.str());
- cloud_path.append("overcast_top_n.rgb");
- normal_map[ SG_CLOUD_OVERCAST ][ 1 ] = new ssgTexture( cloud_path.str().c_str() );
- normal_map[ SG_CLOUD_OVERCAST ][ 1 ]->ref();
-
- cloud_path.set(texture_path.str());
- cloud_path.append("broken.rgba");
- color_map[ SG_CLOUD_BROKEN ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
- color_map[ SG_CLOUD_BROKEN ][ 0 ]->ref();
- cloud_path.set(texture_path.str());
- cloud_path.append("broken_n.rgb");
- normal_map[ SG_CLOUD_BROKEN ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
- normal_map[ SG_CLOUD_BROKEN ][ 0 ]->ref();
-
- cloud_path.set(texture_path.str());
- cloud_path.append("scattered.rgba");
- color_map[ SG_CLOUD_SCATTERED ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
- color_map[ SG_CLOUD_SCATTERED ][ 0 ]->ref();
- cloud_path.set(texture_path.str());
- cloud_path.append("scattered_n.rgb");
- normal_map[ SG_CLOUD_SCATTERED ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
- normal_map[ SG_CLOUD_SCATTERED ][ 0 ]->ref();
-
- cloud_path.set(texture_path.str());
- cloud_path.append("few.rgba");
- color_map[ SG_CLOUD_FEW ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
- color_map[ SG_CLOUD_FEW ][ 0 ]->ref();
- cloud_path.set(texture_path.str());
- cloud_path.append("few_n.rgb");
- normal_map[ SG_CLOUD_FEW ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
- normal_map[ SG_CLOUD_FEW ][ 0 ]->ref();
-
- cloud_path.set(texture_path.str());
- cloud_path.append("cirrus.rgba");
- color_map[ SG_CLOUD_CIRRUS ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
- color_map[ SG_CLOUD_CIRRUS ][ 0 ]->ref();
- cloud_path.set(texture_path.str());
- cloud_path.append("cirrus_n.rgb");
- normal_map[ SG_CLOUD_CIRRUS ][ 0 ] = new ssgTexture( cloud_path.str().c_str() );
- normal_map[ SG_CLOUD_CIRRUS ][ 0 ]->ref();
-
- glGenTextures( 1, &normalization_cube_map );
- glBindTexture( GL_TEXTURE_CUBE_MAP_ARB, normalization_cube_map );
- generateNormalizationCubeMap();
- glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
- glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
- } /* else */ {
- SGPath cloud_path;
- ssgStateSelector *state_sel;
- ssgSimpleState *state;
-
- state_sel = new ssgStateSelector( 2 );
- state_sel->ref();
- cloud_path.set(texture_path.str());
- cloud_path.append("overcast.rgb");
- state_sel->setStep( 0, sgCloudMakeState(cloud_path.str()) );
- cloud_path.set(texture_path.str());
- cloud_path.append("overcast_top.rgb");
- state_sel->setStep( 1, sgCloudMakeState(cloud_path.str()) );
- layer_states[SG_CLOUD_OVERCAST] = state_sel;
-
- state_sel = new ssgStateSelector( 2 );
- state_sel->ref();
- cloud_path.set(texture_path.str());
- cloud_path.append("broken.rgba");
- state = sgCloudMakeState(cloud_path.str());
- state_sel->setStep( 0, state );
- state_sel->setStep( 1, state );
- layer_states[SG_CLOUD_BROKEN] = state_sel;
-
- state_sel = new ssgStateSelector( 2 );
- state_sel->ref();
- cloud_path.set(texture_path.str());
- cloud_path.append("scattered.rgba");
- state = sgCloudMakeState(cloud_path.str());
- state_sel->setStep( 0, state );
- state_sel->setStep( 1, state );
- layer_states[SG_CLOUD_SCATTERED] = state_sel;
-
- state_sel = new ssgStateSelector( 2 );
- state_sel->ref();
- cloud_path.set(texture_path.str());
- cloud_path.append("few.rgba");
- state = sgCloudMakeState(cloud_path.str());
- state_sel->setStep( 0, state );
- state_sel->setStep( 1, state );
- layer_states[SG_CLOUD_FEW] = state_sel;
-
- state_sel = new ssgStateSelector( 2 );
- state_sel->ref();
- cloud_path.set(texture_path.str());
- cloud_path.append("cirrus.rgba");
- state = sgCloudMakeState(cloud_path.str());
- state_sel->setStep( 0, state );
- state_sel->setStep( 1, state );
- layer_states[SG_CLOUD_CIRRUS] = state_sel;
-
- layer_states[SG_CLOUD_CLEAR] = 0;
- }
- }
-
- if ( bump_mapping ) {
-
- if ( !vertices ) {
- vertices = new CloudVertex[ 25 ];
- indices = new unsigned int[ 40 ];
+ osg::Texture::Extensions* extensions;
+ extensions = osg::Texture::getExtensions(0, true);
+ // OSGFIXME
+ bump_mapping = extensions->isMultiTexturingSupported() &&
+ (2 <= extensions->numTextureUnits()) &&
+ SGIsOpenGLExtensionSupported("GL_ARB_texture_env_combine") &&
+ SGIsOpenGLExtensionSupported("GL_ARB_texture_env_dot3");
+
+ osg::TextureCubeMap::Extensions* extensions2;
+ extensions2 = osg::TextureCubeMap::getExtensions(0, true);
+ bump_mapping = bump_mapping && extensions2->isCubeMapSupported();
+
+ // This bump mapping code was inspired by the tutorial available at
+ // http://www.paulsprojects.net/tutorials/simplebump/simplebump.html
+ // and a NVidia white paper
+ // http://developer.nvidia.com/object/bumpmappingwithregistercombiners.html
+ // The normal map textures were generated by the normal map Gimp plugin :
+ // http://nifelheim.dyndns.org/~cocidius/normalmap/
+ //
+ cubeMap = new osg::TextureCubeMap;
+ cubeMap->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
+ cubeMap->setFilter(osg::Texture::MAG_FILTER, osg::Texture::LINEAR);
+ cubeMap->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
+ cubeMap->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
+ cubeMap->setWrap(osg::Texture::WRAP_R, osg::Texture::CLAMP_TO_EDGE);
+
+ const int size = 32;
+ const float half_size = 16.0f;
+ const float offset = 0.5f;
+ osg::Vec3 zero_normal(0.5, 0.5, 0.5);
+
+ osg::Image* image = new osg::Image;
+ image->allocateImage(size, size, 1, GL_RGB, GL_UNSIGNED_BYTE);
+ unsigned char *ptr = image->data(0, 0);
+ for (int j = 0; j < size; j++ ) {
+ for (int i = 0; i < size; i++ ) {
+ osg::Vec3 tmp(half_size, -( j + offset - half_size ),
+ -( i + offset - half_size ) );
+ tmp.normalize();
+ tmp = tmp*0.5 - zero_normal;
+
+ *ptr++ = (unsigned char)( tmp[ 0 ] * 255 );
+ *ptr++ = (unsigned char)( tmp[ 1 ] * 255 );
+ *ptr++ = (unsigned char)( tmp[ 2 ] * 255 );
+ }