home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 2000 April & May / AMIGA_2000_04.iso / patches / mesa3.1 / mesa-3_1.lha / src / AOS / wrpDisplay / wrpFog.c < prev    next >
Encoding:
Text File  |  1999-09-23  |  2.2 KB  |  81 lines

  1. /*
  2.  * $Id: $
  3.  */
  4.  
  5. /*
  6.  * Mesa 3-D graphics library
  7.  * Version:  3.1
  8.  * Copyright (C) 1995  Brian Paul  (brianp@ssec.wisc.edu)
  9.  *
  10.  * This library is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU Library General Public
  12.  * License as published by the Free Software Foundation; either
  13.  * version 2 of the License, or (at your option) any later version.
  14.  *
  15.  * This library is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * Library General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU Library General Public
  21.  * License along with this library; if not, write to the Free
  22.  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. void wrpSetupFog(GLcontext * ctx)
  26. {
  27.   struct TDdriver *TDdriver;
  28.   W3D_Context *TDcontext;
  29.   W3D_Fog fog;
  30.   W3D_Float wscale;
  31.   GLuint fogmode;
  32.  
  33.   DEBUGOUT(1, "wrpDepthTestSpan()\n");
  34.  
  35.   TDdriver = ((amigaMesaContext) ctx->DriverCtx)->TDdriver;
  36.   TDcontext = TDdriver->td_ctx;
  37.   wscale = TDdriver->wscale;
  38.  
  39.   if (ctx->Fog.Mode == GL_LINEAR) {
  40.     fog.fog_start = (1 / ctx->Fog.Start) * wscale;
  41.     fog.fog_end = (1 / ctx->Fog.End) * wscale;
  42.   }
  43.   else {
  44.     fog.fog_start = 1.0;
  45.     fog.fog_end = (1 / TDdriver->far) * wscale;
  46.   }
  47.  
  48.   fog.fog_density = ctx->Fog.Density / wscale;
  49.  
  50.   if (ctx->Visual->RGBAflag) {
  51.     fog.fog_color.r = ctx->Fog.Color[0];
  52.     fog.fog_color.g = ctx->Fog.Color[1];
  53.     fog.fog_color.b = ctx->Fog.Color[2];
  54.   }
  55.   else {
  56.     GLuint index = ctx->Fog.Index;
  57.  
  58.     fog.fog_color.r = (W3D_Float) (TDdriver->Palette[index].r / 255.0);
  59.     fog.fog_color.g = (W3D_Float) (TDdriver->Palette[index].g / 255.0);
  60.     fog.fog_color.b = (W3D_Float) (TDdriver->Palette[index].b / 255.0);
  61.   }
  62.  
  63.   switch (ctx->Fog.Mode) {
  64.     case GL_LINEAR:
  65.       fogmode = W3D_FOG_LINEAR;
  66.       if (W3D_Query(TDcontext, W3D_Q_LINEAR, NULL) == W3D_NOT_SUPPORTED)
  67.     fogmode = W3D_FOG_INTERPOLATED;
  68.       break;
  69.     case GL_EXP:
  70.       fogmode = W3D_FOG_EXP;
  71.       break;
  72.     case GL_EXP2:
  73.       fogmode = W3D_FOG_EXP_2;
  74.       break;
  75.     default:
  76.       return;
  77.   }
  78.  
  79.   W3D_SetFogParams(TDcontext, &fog, fogmode);
  80. }
  81.