Anyone can help me on fogs in gl ? thanks

i’ve been recently developing a software 3d rendering engine , just for fun , and for better understanding of the 3d rendering algorithms and opengl. i can project the geometry properly on the screen now , and use textures on the surface of the polygons , but now i want to use fogs in my texture shading, i just can’t figure out any efficient algorithms on it , andbody can give me anyhelp please~~ thanks, btw, i’m totaly a noob on gl stuff, lol~~~~

where can i see any exampel of your software renderer?

okay , here is the link to the code , but all these things are in java , since it makes things easier although there might be some defects in performance.
http://www.bronzeshow.com/Graphics.rar

all the texture mapping and geometry clipings are in Graphic3d.java ,and it used an integer array as a image buffer, and every pixels are in ARGB 32bit format. And all texture mapping was in a method called fillTriangle.
THX.

BTW, jdk1.5 might be required

Fog isn’t directly related to texturing. It simply takes the fragment’s post texturing color, and blends it with the fog color based on the fragment’s depth value.

  depth: fragment's depth value
  fog(): fog equation (see gl spec)
  Cf:    fog color
  Cr:    fragment color after shading and texturing
  C:     fragment color after fogging

  f = clamp(fog(depth));
  C = f*Cr + (1-f)*Cf

The exact specification is in Chapter 3.10 Fog, on page 191 of the OpenGL 2.0 Specification .