/** * Draws the heightfield represented by this tree * Returns teh number of triangles rendered (not including multipass */ int quadsquare::Render( const quadcornerdata &cd, const Vector &camvec ) { quadsquare::camerapos = camvec; vertices->LoadDrawState(); vertices->BeginDrawState( GFXFALSE ); int totsize = 0; RenderAux( cd, GFX_PARTIALLY_VISIBLE ); vecTextureIndex::iterator i = indices.begin(); vecTextureStar::iterator k; for (k = textures->begin(); k != textures->end(); i++, k++) { TerrainMakeActive( *k ); unsigned int isize = (*i).q.size(); totsize += isize; vertices->Draw( GFXTRI, isize, (*i).q.begin() ); TerrainMakeDeactive( *k ); } vertices->EndDrawState(); i = indices.begin(); int j = 0; for (k = textures->begin(); k != textures->end(); i++, j++, k++) { if ( (*i).c.size() > 2 ) { TerrainMakeClearActive( *k ); GFXPolygonOffset( 0, -j ); GFXColorMaterial( AMBIENT|DIFFUSE ); GFXColorVertex **cv = (&blendVertices->BeginMutate( 0 )->colors); GFXColorVertex *tmp = *cv; *cv = (*i).c.begin(); blendVertices->EndMutate( (*i).c.size() ); blendVertices->LoadDrawState(); blendVertices->BeginDrawState( GFXFALSE ); blendVertices->Draw( GFXTRI, (*i).c.size() ); blendVertices->EndDrawState( GFXFALSE ); cv = (&blendVertices->BeginMutate( 0 )->colors); *cv = tmp; blendVertices->EndMutate( 3 ); GFXColorMaterial( 0 ); GFXPolygonOffset( 0, 0 ); TerrainMakeDeactive( *k ); } (*i).Clear(); } return totsize; }
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 ); }