/*! Draws a fog plane at the far clipping plane to mask out clipping of terrain. \return none \author jfpatry \date Created: 2000-08-31 \date Modified: 2000-08-31 */ void draw_fog_plane() { plane_t left_edge_plane, right_edge_plane; plane_t left_clip_plane, right_clip_plane; plane_t far_clip_plane; plane_t bottom_clip_plane; plane_t bottom_plane, top_plane; scalar_t course_width, course_length; scalar_t course_angle, slope; point_t left_pt, right_pt, pt; point_t top_left_pt, top_right_pt; point_t bottom_left_pt, bottom_right_pt; vector_t left_vec, right_vec; scalar_t height; GLfloat *fog_colour; if ( is_fog_on() == False ) { return; } set_gl_options( FOG_PLANE ); get_course_dimensions( &course_width, &course_length ); course_angle = get_course_angle(); slope = tan( ANGLES_TO_RADIANS( course_angle ) ); left_edge_plane = make_plane( 1.0, 0.0, 0.0, 0.0 ); right_edge_plane = make_plane( -1.0, 0.0, 0.0, course_width ); far_clip_plane = get_far_clip_plane(); left_clip_plane = get_left_clip_plane(); right_clip_plane = get_right_clip_plane(); bottom_clip_plane = get_bottom_clip_plane(); /* Find the bottom plane */ bottom_plane.nml = make_vector( 0.0, 1, -slope ); height = get_terrain_base_height( 0 ); /* Unoptimized version pt = make_point( 0, height, 0 ); bottom_plane.d = -( pt.x * bottom_plane.nml.x + pt.y * bottom_plane.nml.y + pt.z * bottom_plane.nml.z ); */ bottom_plane.d = -height * bottom_plane.nml.y; /* Find the top plane */ top_plane.nml = bottom_plane.nml; height = get_terrain_max_height( 0 ); top_plane.d = -height * top_plane.nml.y; if(get_player_data(local_player())->view.mode == TUXEYE) { bottom_clip_plane.nml = make_vector( 0.0, 1, -slope ); height = get_terrain_base_height( 0 ) - 40; bottom_clip_plane.d = -height * bottom_clip_plane.nml.y; } /* Now find the bottom left and right points of the fog plane */ if ( !intersect_planes( bottom_plane, far_clip_plane, left_clip_plane, &left_pt ) ) return; if ( !intersect_planes( bottom_plane, far_clip_plane, right_clip_plane, &right_pt ) ) return; if ( !intersect_planes( top_plane, far_clip_plane, left_clip_plane, &top_left_pt ) ) return; if ( !intersect_planes( top_plane, far_clip_plane, right_clip_plane, &top_right_pt ) ) return; if ( !intersect_planes( bottom_clip_plane, far_clip_plane, left_clip_plane, &bottom_left_pt ) ) return; if ( !intersect_planes( bottom_clip_plane, far_clip_plane, right_clip_plane, &bottom_right_pt ) ) return; left_vec = subtract_points( top_left_pt, left_pt ); right_vec = subtract_points( top_right_pt, right_pt ); /* Now draw the fog plane */ set_gl_options( FOG_PLANE ); fog_colour = get_fog_colour(); glColor4fv( fog_colour ); #ifdef __APPLE__DISABLED__ #undef glEnableClientState #undef glDisableClientState #undef glVertexPointer #undef glColorPointer #undef glDrawArrays point_t pt1,pt2,pt3,pt4; pt1 = move_point( top_left_pt, left_vec ); pt2 = move_point( top_right_pt, right_vec ); pt3 = move_point( top_left_pt, scale_vector( 3.0, left_vec ) ); pt4 = move_point( top_right_pt, scale_vector( 3.0, right_vec ) ); const GLfloat verticesFog []= { bottom_left_pt.x, bottom_left_pt.y, bottom_left_pt.z, bottom_right_pt.x, bottom_right_pt.y, bottom_right_pt.z, left_pt.x, left_pt.y, left_pt.z, right_pt.x, right_pt.y, right_pt.z, top_left_pt.x, top_left_pt.y, top_left_pt.z, top_right_pt.x, top_right_pt.y, top_right_pt.z, pt1.x, pt1.y, pt1.z, pt2.x, pt2.y, pt2.z, pt3.x, pt3.y, pt3.z, pt4.x, pt4.y, pt4.z }; const GLfloat colorsFog []= { fog_colour[0], fog_colour[1], fog_colour[2], fog_colour[3], fog_colour[0], fog_colour[1], fog_colour[2], fog_colour[3], fog_colour[0], fog_colour[1], fog_colour[2], fog_colour[3], fog_colour[0], fog_colour[1], fog_colour[2], fog_colour[3], fog_colour[0], fog_colour[1], fog_colour[2], 0.9 , fog_colour[0], fog_colour[1], fog_colour[2], 0.9 , fog_colour[0], fog_colour[1], fog_colour[2], 0.3 , fog_colour[0], fog_colour[1], fog_colour[2], 0.3 , fog_colour[0], fog_colour[1], fog_colour[2], 0.0 , fog_colour[0], fog_colour[1], fog_colour[2], 0.0 , }; glEnableClientState (GL_VERTEX_ARRAY); // glEnableClientState (GL_COLOR_ARRAY); // glDisableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer (3, GL_FLOAT , 0, verticesFog); glColorPointer(4, GL_FLOAT, 0, colorsFog); glDrawArrays(GL_TRIANGLE_STRIP, 0, 10); //glDisableClientState(GL_COLOR_ARRAY_POINTER); #else glBegin( GL_QUAD_STRIP ); glVertex3f( bottom_left_pt.x, bottom_left_pt.y, bottom_left_pt.z ); glVertex3f( bottom_right_pt.x, bottom_right_pt.y, bottom_right_pt.z ); glVertex3f( left_pt.x, left_pt.y, left_pt.z ); glVertex3f( right_pt.x, right_pt.y, right_pt.z ); glColor4f( fog_colour[0], fog_colour[1], fog_colour[2], 0.9 ); glVertex3f( top_left_pt.x, top_left_pt.y, top_left_pt.z ); glVertex3f( top_right_pt.x, top_right_pt.y, top_right_pt.z ); glColor4f( fog_colour[0], fog_colour[1], fog_colour[2], 0.3 ); pt = move_point( top_left_pt, left_vec ); glVertex3f( pt.x, pt.y, pt.z ); pt = move_point( top_right_pt, right_vec ); glVertex3f( pt.x, pt.y, pt.z ); glColor4f( fog_colour[0], fog_colour[1], fog_colour[2], 0.0 ); pt = move_point( top_left_pt, scale_vector( 3.0, left_vec ) ); glVertex3f( pt.x, pt.y, pt.z ); pt = move_point( top_right_pt, scale_vector( 3.0, right_vec ) ); glVertex3f( pt.x, pt.y, pt.z ); glEnd(); #endif }
void quadsquare::Render(const quadcornerdata& cd, GLubyte *vnc_array) // Draws the heightfield represented by this tree. // Returns the number of triangles rendered. { VNCArray = vnc_array; bool_t fog_on; unsigned int i, j; int nx, ny; get_course_divisions( &nx, &ny ); /* Save fog state */ fog_on = is_fog_on(); /* * Draw the "normal" blended triangles ( <= 2 terrains textures ) */ for (j=0; j<NumTerrains; j++) { InitArrayCounters(); RenderAux(cd, SomeClip, j); if ( VertexArrayCounter == 0 ) { continue; } glBindTexture( GL_TEXTURE_2D, TexId[j] ); DrawTris(); if ( j == Ice && getparam_terrain_envmap() ) { /* Render Ice with environment map */ glDisableClientState( GL_COLOR_ARRAY ); glColor4f( 1.0, 1.0, 1.0, ENV_MAP_ALPHA / 255.0 ); DrawEnvmapTris(); glEnableClientState( GL_COLOR_ARRAY ); } } /* * Draw the "special" triangles that have different terrain types * at each of the corners */ if ( getparam_terrain_blending() && getparam_perfect_terrain_blending() ) { /* * Get the "special" three-terrain triangles */ InitArrayCounters(); RenderAux( cd, SomeClip, -1 ); if ( VertexArrayCounter != 0 ) { /* Render black triangles */ glDisable( GL_FOG ); /* Set triangle vertices to black */ for (i=0; i<VertexArrayCounter; i++) { colorval( VertexArrayIndices[i], 0 ) = 0; colorval( VertexArrayIndices[i], 1 ) = 0; colorval( VertexArrayIndices[i], 2 ) = 0; colorval( VertexArrayIndices[i], 3 ) = 255; } /* Draw the black triangles */ glBindTexture( GL_TEXTURE_2D, TexId[0] ); DrawTris(); /* Now we draw the triangle once for each texture */ if (fog_on) { glEnable( GL_FOG ); } /* Use additive blend function */ glBlendFunc( GL_SRC_ALPHA, GL_ONE ); /* First set triangle colours to white */ for (i=0; i<VertexArrayCounter; i++) { colorval( VertexArrayIndices[i], 0 ) = 255; colorval( VertexArrayIndices[i], 1 ) = 255; colorval( VertexArrayIndices[i], 2 ) = 255; } for (j=0; j<NumTerrains; j++) { glBindTexture( GL_TEXTURE_2D, TexId[j] ); /* Set alpha values */ for (i=0; i<VertexArrayCounter; i++) { colorval( VertexArrayIndices[i], 3 ) = (Terrain[VertexArrayIndices[i]] == (terrain_t)j ) ? 255 : 0; } DrawTris(); } /* Render Ice with environment map */ if ( getparam_terrain_envmap() ) { glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); /* Need to set alpha values for ice */ for (i=0; i<VertexArrayCounter; i++) { colorval( VertexArrayIndices[i], 3 ) = (Terrain[VertexArrayIndices[i]] == Ice) ? ENV_MAP_ALPHA : 0; } DrawEnvmapTris(); } } } glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); }