]> icculus.org git repositories - taylor/freespace2.git/blob - src/graphics/line.cpp
Screenshot function filled, will output into ~/.freespace(2)/Data
[taylor/freespace2.git] / src / graphics / line.cpp
1 /*
2  * Copyright (C) Volition, Inc. 1999.  All rights reserved.
3  *
4  * All source code herein is the property of Volition, Inc. You may not sell 
5  * or otherwise commercially exploit the source or things you created based on
6  * the source.
7  */
8
9 /*
10  * $Logfile: /Freespace2/code/Graphics/Line.cpp $
11  * $Revision$
12  * $Date$
13  * $Author$
14  *
15  * Routines for drawing lines.
16  *
17  * $Log$
18  * Revision 1.2  2002/06/09 04:41:18  relnev
19  * added copyright header
20  *
21  * Revision 1.1.1.1  2002/05/03 03:28:09  root
22  * Initial import.
23  *
24  * 
25  * 3     12/02/98 5:47p Dave
26  * Put in interface xstr code. Converted barracks screen to new format.
27  * 
28  * 2     10/07/98 10:53a Dave
29  * Initial checkin.
30  * 
31  * 1     10/07/98 10:49a Dave
32  * 
33  * 21    5/06/98 5:30p John
34  * Removed unused cfilearchiver.  Removed/replaced some unused/little used
35  * graphics functions, namely gradient_h and _v and pixel_sp.   Put in new
36  * DirectX header files and libs that fixed the Direct3D alpha blending
37  * problems.
38  * 
39  * 20    3/10/98 4:18p John
40  * Cleaned up graphics lib.  Took out most unused gr functions.   Made D3D
41  * & Glide have popups and print screen.  Took out all >8bpp software
42  * support.  Made Fred zbuffer.  Made zbuffer allocate dynamically to
43  * support Fred.  Made zbuffering key off of functions rather than one
44  * global variable.
45  * 
46  * 19    1/13/98 10:20a John
47  * Added code to support "glass" in alphacolors
48  * 
49  * 18    11/30/97 12:18p John
50  * added more 24 & 32-bpp primitives
51  * 
52  * 17    11/29/97 2:06p John
53  * added mode 16-bpp support
54  * 
55  * 16    10/19/97 12:55p John
56  * new code to lock / unlock surfaces for smooth directx integration.
57  * 
58  * 15    10/14/97 8:08a John
59  * added a bunch more 16 bit support
60  * 
61  * 14    10/03/97 9:10a John
62  * added better antialiased line drawer
63  * 
64  * 13    9/09/97 10:39a Sandeep
65  * Fixed compiler warnings level 4 (sorta, john is fixing most of it)
66  * 
67  * 12    6/13/97 5:35p John
68  * added some antialiased bitmaps and lines
69  * 
70  * 11    6/06/97 2:40p John
71  * Made all the radar dim in/out
72  * 
73  * 10    5/12/97 12:27p John
74  * Restructured Graphics Library to add support for multiple renderers.
75  * 
76  * 9     11/26/96 6:50p John
77  * Added some more hicolor primitives.  Made windowed mode run as current
78  * bpp, if bpp is 8,16,or 32.
79  * 
80  * 8     10/26/96 2:56p John
81  * Got gradient code working.
82  * 
83  * 7     10/26/96 1:40p John
84  * Added some now primitives to the 2d library and
85  * cleaned up some old ones.
86  *
87  * $NoKeywords: $
88  */
89
90 #ifndef PLAT_UNIX
91 #include <windows.h>
92 #include <windowsx.h>
93 #endif
94
95 #include "2d.h"
96 #include "grinternal.h"
97 #include "floating.h"
98 #include "line.h"
99 #include "key.h"
100
101
102 void gr8_uline(int x1,int y1,int x2,int y2)
103 {
104         int i;
105    int xstep,ystep;
106    int dy=y2-y1;
107    int dx=x2-x1;
108    int error_term=0;
109
110         gr_lock();
111         ubyte *dptr = GR_SCREEN_PTR(ubyte,x1,y1);
112         ubyte color = gr_screen.current_color.raw8;
113                 
114         if(dy<0)        {
115                 dy=-dy;
116       ystep=-gr_screen.rowsize / gr_screen.bytes_per_pixel;
117         }       else    {
118       ystep=gr_screen.rowsize / gr_screen.bytes_per_pixel;
119         }
120
121    if(dx<0)     {
122       dx=-dx;
123       xstep=-1;
124    } else {
125       xstep=1;
126         }
127
128         /* HARDWARE_ONLY - removed alpha color table stuff
129         if ( Current_alphacolor )       {
130                 if(dx>dy)       {
131
132                         for(i=dx+1;i>0;i--) {
133                                 *dptr = Current_alphacolor->table.lookup[14][*dptr];
134                                 dptr += xstep;
135                                 error_term+=dy;
136
137                                 if(error_term>dx)       {
138                                         error_term-=dx;
139                                         dptr+=ystep;
140                                 }
141                         }
142                 } else {
143
144                         for(i=dy+1;i>0;i--)     {
145                                 *dptr = Current_alphacolor->table.lookup[14][*dptr];
146                                 dptr += ystep;
147                                 error_term+=dx;
148                                 if(error_term>0)        {
149                                         error_term-=dy;
150                                         dptr+=xstep;
151                                 }
152
153                         }
154
155                 }
156         } else {
157         */
158                 if(dx>dy)       {
159
160                         for(i=dx+1;i>0;i--) {
161                                 *dptr = color;
162                                 dptr += xstep;
163                                 error_term+=dy;
164
165                                 if(error_term>dx)       {
166                                         error_term-=dx;
167                                         dptr+=ystep;
168                                 }
169                         }
170                 } else {
171
172                         for(i=dy+1;i>0;i--)     {
173                                 *dptr = color;
174                                 dptr += ystep;
175                                 error_term+=dx;
176                                 if(error_term>0)        {
177                                         error_term-=dy;
178                                         dptr+=xstep;
179                                 }
180
181                         }
182
183                 }       
184         gr_unlock();
185 }  
186
187
188
189 void gr8_line(int x1,int y1,int x2,int y2)
190 {
191         int clipped = 0, swapped=0;
192
193         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);
194
195         gr8_uline(x1,y1,x2,y2);
196 }
197
198
199