]> icculus.org git repositories - taylor/freespace2.git/blob - src/graphics/gradient.cpp
Initial revision
[taylor/freespace2.git] / src / graphics / gradient.cpp
1 /*
2  * $Logfile: /Freespace2/code/Graphics/Gradient.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Routines to draw rectangular gradients.
8  *
9  * $Log$
10  * Revision 1.1  2002/05/03 03:28:09  root
11  * Initial revision
12  *
13  * 
14  * 3     12/02/98 5:47p Dave
15  * Put in interface xstr code. Converted barracks screen to new format.
16  * 
17  * 2     10/07/98 10:52a Dave
18  * Initial checkin.
19  * 
20  * 1     10/07/98 10:49a Dave
21  * 
22  * 17    5/06/98 5:30p John
23  * Removed unused cfilearchiver.  Removed/replaced some unused/little used
24  * graphics functions, namely gradient_h and _v and pixel_sp.   Put in new
25  * DirectX header files and libs that fixed the Direct3D alpha blending
26  * problems.
27  * 
28  * 16    3/10/98 4:18p John
29  * Cleaned up graphics lib.  Took out most unused gr functions.   Made D3D
30  * & Glide have popups and print screen.  Took out all >8bpp software
31  * support.  Made Fred zbuffer.  Made zbuffer allocate dynamically to
32  * support Fred.  Made zbuffering key off of functions rather than one
33  * global variable.
34  * 
35  * 15    1/19/98 6:15p John
36  * Fixed all my Optimized Build compiler warnings
37  * 
38  * 14    11/30/97 4:04p John
39  * 
40  * 13    11/30/97 12:18p John
41  * added more 24 & 32-bpp primitives
42  * 
43  * 12    10/19/97 12:55p John
44  * new code to lock / unlock surfaces for smooth directx integration.
45  * 
46  * 11    10/14/97 4:50p John
47  * more 16 bpp stuff.
48  * 
49  * 10    10/14/97 8:08a John
50  * added a bunch more 16 bit support
51  * 
52  * 9     10/09/97 5:23p John
53  * Added support for more 16-bpp functions
54  * 
55  * 8     6/11/97 1:12p John
56  * Started fixing all the text colors in the game.
57  * 
58  * 7     5/12/97 12:27p John
59  * Restructured Graphics Library to add support for multiple renderers.
60  * 
61  * 6     12/12/96 4:59p Lawrance
62  * made clipping for horizontal and vertical gradient lines right
63  * 
64  * 5     11/19/96 2:46p Allender
65  * fix up gradient support for 15bpp
66  * 
67  * 4     11/18/96 4:34p Allender
68  * new 16 bit gradient functions
69  * 
70  * 3     10/27/96 1:21a Lawrance
71  * added check to avoid divide by zero when calculating gradients
72  * 
73  * 2     10/26/96 2:56p John
74  * Got gradient code working.
75  * 
76  * 1     10/26/96 1:45p John
77  * Initial skeletion code.
78  *
79  * $NoKeywords: $
80  */
81
82 #ifndef PLAT_UNIX
83 #include <windows.h>
84 #include <windowsx.h>
85 #endif
86
87 #include "2d.h"
88 #include "grinternal.h"
89 #include "gradient.h"
90 #include "floating.h"
91 #include "line.h"
92 #include "palman.h"
93                 
94 void gr8_gradient(int x1,int y1,int x2,int y2)
95 {
96 #ifndef HARDWARE_ONLY
97         int i;
98    int xstep,ystep;
99         int clipped = 0, swapped=0;
100         ubyte *xlat_table;
101
102         int l=0, dl=0;
103
104         if (!Current_alphacolor) {
105                 gr_line( x1, y1, x2, y2 );
106                 return;
107         }
108
109         INT_CLIPLINE(x1,y1,x2,y2,gr_screen.clip_left,gr_screen.clip_top,gr_screen.clip_right,gr_screen.clip_bottom,return,clipped=1,swapped=1);
110
111    int dy=y2-y1;
112    int dx=x2-x1;
113    int error_term=0;
114
115         if ( dx==0 && dy==0 )   {
116                 return;
117         }
118
119         gr_lock();
120
121         ubyte *dptr = GR_SCREEN_PTR(ubyte,x1,y1);
122
123         xlat_table = (ubyte *)&Current_alphacolor->table.lookup[0][0];
124
125         
126         if(dy<0)        {
127                 dy=-dy;
128       ystep=-gr_screen.rowsize / gr_screen.bytes_per_pixel;
129         }       else    {
130       ystep=gr_screen.rowsize / gr_screen.bytes_per_pixel;
131         }
132
133    if(dx<0)     {
134       dx=-dx;
135       xstep=-1;
136    } else {
137       xstep=1;
138         }
139
140         if(dx>dy)       {
141
142                 if (!swapped)   {
143                         l = 14<<8;
144                         dl = (-14<<8) / dx;
145                 } else {
146                         l = 0;
147                         dl = (14<<8) / dx;
148                 }       
149
150                 for(i=0;i<dx;i++) {
151                         *dptr = xlat_table[(l&0xF00)|*dptr];
152                         l += dl;
153                         dptr += xstep;
154          error_term+=dy;
155
156          if(error_term>dx)      {
157                                 error_term-=dx;
158             dptr+=ystep;
159          }
160       }
161                 *dptr = xlat_table[(l&0xF00)|*dptr];
162
163    } else {
164
165                 if (!swapped)   {
166                         l = 14<<8;
167                         dl = (-14<<8) / dy;
168                 } else {
169                         l = 0;
170                         dl = (14<<8) / dy;
171                 }       
172
173       for(i=0;i<dy;i++) {
174                         *dptr = xlat_table[(l&0xF00)|*dptr];
175                         l += dl;
176                         dptr += ystep;
177          error_term+=dx;
178          if(error_term>0)       {
179             error_term-=dy;
180             dptr+=xstep;
181          }
182
183       }
184                 *dptr = xlat_table[(l&0xF00)|*dptr];
185
186    }
187         gr_unlock();
188 #else 
189         Int3();
190 #endif
191 }
192
193
194                 
195
196