static glActiveTextureProc glActiveTexturePtr = 0;
static glClientActiveTextureProc glClientActiveTexturePtr = 0;
+static glBlendColorProc glBlendColorPtr = 0;
bool SGCloudLayer::enable_bump_mapping = false;
bump_mapping = SGIsOpenGLExtensionSupported("GL_ARB_multitexture") &&
SGIsOpenGLExtensionSupported("GL_ARB_texture_cube_map") &&
SGIsOpenGLExtensionSupported("GL_ARB_texture_env_combine") &&
- SGIsOpenGLExtensionSupported("GL_ARB_texture_env_dot3") && true;
+ 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 ) {
glActiveTexturePtr = (glActiveTextureProc)SGLookupFunction("glActiveTextureARB");
glClientActiveTexturePtr = (glClientActiveTextureProc)SGLookupFunction("glClientActiveTextureARB");
+ glBlendColorPtr = (glBlendColorProc)SGLookupFunction("glBlendColor");
cloud_path.set(texture_path.str());
cloud_path.append("overcast.rgb");
glDisable( GL_LIGHTING );
glDisable( GL_CULL_FACE );
- glEnable( GL_ALPHA_TEST );
- glAlphaFunc ( GL_GREATER, 0.1 ) ;
+ if ( layer_coverage == SG_CLOUD_FEW ) {
+ glEnable( GL_ALPHA_TEST );
+ glAlphaFunc ( GL_GREATER, 0.01 );
+ }
glEnable( GL_BLEND );
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_RGB_ARB, GL_TEXTURE );
glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_RGB_ARB, GL_DOT3_RGB_ARB );
glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE1_RGB_ARB, GL_PREVIOUS_ARB );
+ glTexEnvi( GL_TEXTURE_ENV, GL_SOURCE0_ALPHA_ARB, GL_PREVIOUS_ARB );
+ glTexEnvi( GL_TEXTURE_ENV, GL_COMBINE_ALPHA_ARB, GL_REPLACE );
if ( nb_texture_unit >= 3 ) {
glActiveTexturePtr( GL_TEXTURE2_ARB );
glClientActiveTexturePtr( GL_TEXTURE0_ARB );
glDisableClientState( GL_COLOR_ARRAY );
+ glEnable( GL_LIGHTING );
+
+ glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
} else {
glClientActiveTexturePtr( GL_TEXTURE0_ARB );
glDrawElements( GL_TRIANGLE_STRIP, 10, GL_UNSIGNED_INT, &indices[20] );
glDrawElements( GL_TRIANGLE_STRIP, 10, GL_UNSIGNED_INT, &indices[30] );
-
//Disable textures
glDisable( GL_TEXTURE_2D );
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glDepthFunc(GL_LEQUAL);
- //Enable multiplicative blending
- glBlendFunc( GL_DST_COLOR, GL_ZERO );
+
+ glEnable( GL_LIGHTING );
+ sgVec4 color;
+ ssgGetLight( 0 )->getColour( GL_DIFFUSE, color );
+ float average = ( color[0] + color[1] + color[2] ) / 3.0f;
+ sgVec4 averageColor;
+ sgSetVec4( averageColor, average, average, average, 1.0f );
+ ssgGetLight( 0 )->setColour( GL_DIFFUSE, averageColor );
+
+ glBlendColorPtr( average, average, average, 1.0f );
+ glBlendFunc( GL_ONE_MINUS_CONSTANT_COLOR, GL_CONSTANT_COLOR );
//Perform a second pass to color the torus
//Bind decal texture
glDrawElements( GL_TRIANGLE_STRIP, 10, GL_UNSIGNED_INT, &indices[20] );
glDrawElements( GL_TRIANGLE_STRIP, 10, GL_UNSIGNED_INT, &indices[30] );
+ ssgGetLight( 0 )->setColour( GL_DIFFUSE, color );
+
glDisableClientState( GL_TEXTURE_COORD_ARRAY );
}
//Disable texture
glDisableClientState( GL_VERTEX_ARRAY );
glDisableClientState( GL_NORMAL_ARRAY );
- glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-
glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
- glEnable( GL_LIGHTING );
glEnable( GL_CULL_FACE );
glDepthFunc(GL_LESS);
* OpenGL 1.2 and 1.3 enumerants
*/
-#ifndef GL_CLAMP_TO_EDGE
+#ifndef GL_VERSION_1_2
#define GL_CLAMP_TO_EDGE 0x812F
-#endif
-
-#ifndef GL_TEXTURE_WRAP_R
#define GL_TEXTURE_WRAP_R 0x8072
-#endif
+#define GL_BLEND_EQUATION 0x8009
+#define GL_MIN 0x8007
+#define GL_MAX 0x8008
+#define GL_FUNC_ADD 0x8006
+#define GL_FUNC_SUBTRACT 0x800A
+#define GL_FUNC_REVERSE_SUBTRACT 0x800B
+#define GL_BLEND_COLOR 0x8005
+#define GL_CONSTANT_COLOR 0x8001
+#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
+#define GL_CONSTANT_ALPHA 0x8003
+#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
+#endif
+
+typedef void (APIENTRY * glBlendEquationProc) (GLenum mode );
+typedef void (APIENTRY * glBlendColorProc) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha );
/* OpenGL extension declarations */