]> icculus.org git repositories - taylor/freespace2.git/blob - src/graphics/line.cpp
Initial revision
[taylor/freespace2.git] / src / graphics / line.cpp
1 /*
2  * $Logfile: /Freespace2/code/Graphics/Line.cpp $
3  * $Revision$
4  * $Date$
5  * $Author$
6  *
7  * Routines for drawing lines.
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:53a Dave
18  * Initial checkin.
19  * 
20  * 1     10/07/98 10:49a Dave
21  * 
22  * 21    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  * 20    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  * 19    1/13/98 10:20a John
36  * Added code to support "glass" in alphacolors
37  * 
38  * 18    11/30/97 12:18p John
39  * added more 24 & 32-bpp primitives
40  * 
41  * 17    11/29/97 2:06p John
42  * added mode 16-bpp support
43  * 
44  * 16    10/19/97 12:55p John
45  * new code to lock / unlock surfaces for smooth directx integration.
46  * 
47  * 15    10/14/97 8:08a John
48  * added a bunch more 16 bit support
49  * 
50  * 14    10/03/97 9:10a John
51  * added better antialiased line drawer
52  * 
53  * 13    9/09/97 10:39a Sandeep
54  * Fixed compiler warnings level 4 (sorta, john is fixing most of it)
55  * 
56  * 12    6/13/97 5:35p John
57  * added some antialiased bitmaps and lines
58  * 
59  * 11    6/06/97 2:40p John
60  * Made all the radar dim in/out
61  * 
62  * 10    5/12/97 12:27p John
63  * Restructured Graphics Library to add support for multiple renderers.
64  * 
65  * 9     11/26/96 6:50p John
66  * Added some more hicolor primitives.  Made windowed mode run as current
67  * bpp, if bpp is 8,16,or 32.
68  * 
69  * 8     10/26/96 2:56p John
70  * Got gradient code working.
71  * 
72  * 7     10/26/96 1:40p John
73  * Added some now primitives to the 2d library and
74  * cleaned up some old ones.
75  *
76  * $NoKeywords: $
77  */
78
79 #ifndef PLAT_UNIX
80 #include <windows.h>
81 #include <windowsx.h>
82 #endif
83
84 #include "2d.h"
85 #include "grinternal.h"
86 #include "floating.h"
87 #include "line.h"
88 #include "key.h"
89
90
91 void gr8_uline(int x1,int y1,int x2,int y2)
92 {
93         int i;
94    int xstep,ystep;
95    int dy=y2-y1;
96    int dx=x2-x1;
97    int error_term=0;
98
99         gr_lock();
100         ubyte *dptr = GR_SCREEN_PTR(ubyte,x1,y1);
101         ubyte color = gr_screen.current_color.raw8;
102                 
103         if(dy<0)        {
104                 dy=-dy;
105       ystep=-gr_screen.rowsize / gr_screen.bytes_per_pixel;
106         }       else    {
107       ystep=gr_screen.rowsize / gr_screen.bytes_per_pixel;
108         }
109
110    if(dx<0)     {
111       dx=-dx;
112       xstep=-1;
113    } else {
114       xstep=1;
115         }
116
117         /* HARDWARE_ONLY - removed alpha color table stuff
118         if ( Current_alphacolor )       {
119                 if(dx>dy)       {
120
121                         for(i=dx+1;i>0;i--) {
122                                 *dptr = Current_alphacolor->table.lookup[14][*dptr];
123                                 dptr += xstep;
124                                 error_term+=dy;
125
126                                 if(error_term>dx)       {
127                                         error_term-=dx;
128                                         dptr+=ystep;
129                                 }
130                         }
131                 } else {
132
133                         for(i=dy+1;i>0;i--)     {
134                                 *dptr = Current_alphacolor->table.lookup[14][*dptr];
135                                 dptr += ystep;
136                                 error_term+=dx;
137                                 if(error_term>0)        {
138                                         error_term-=dy;
139                                         dptr+=xstep;
140                                 }
141
142                         }
143
144                 }
145         } else {
146         */
147                 if(dx>dy)       {
148
149                         for(i=dx+1;i>0;i--) {
150                                 *dptr = color;
151                                 dptr += xstep;
152                                 error_term+=dy;
153
154                                 if(error_term>dx)       {
155                                         error_term-=dx;
156                                         dptr+=ystep;
157                                 }
158                         }
159                 } else {
160
161                         for(i=dy+1;i>0;i--)     {
162                                 *dptr = color;
163                                 dptr += ystep;
164                                 error_term+=dx;
165                                 if(error_term>0)        {
166                                         error_term-=dy;
167                                         dptr+=xstep;
168                                 }
169
170                         }
171
172                 }       
173         gr_unlock();
174 }  
175
176
177
178 void gr8_line(int x1,int y1,int x2,int y2)
179 {
180         int clipped = 0, swapped=0;
181
182         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);
183
184         gr8_uline(x1,y1,x2,y2);
185 }
186
187
188