]> icculus.org git repositories - btb/d2x.git/blob - unused/vga/grx.h
replaced by maths.h
[btb/d2x.git] / unused / vga / grx.h
1 /*
2 THE COMPUTER CODE CONTAINED HEREIN IS THE SOLE PROPERTY OF PARALLAX
3 SOFTWARE CORPORATION ("PARALLAX").  PARALLAX, IN DISTRIBUTING THE CODE TO
4 END-USERS, AND SUBJECT TO ALL OF THE TERMS AND CONDITIONS HEREIN, GRANTS A
5 ROYALTY-FREE, PERPETUAL LICENSE TO SUCH END-USERS FOR USE BY SUCH END-USERS
6 IN USING, DISPLAYING,  AND CREATING DERIVATIVE WORKS THEREOF, SO LONG AS
7 SUCH USE, DISPLAY OR CREATION IS FOR NON-COMMERCIAL, ROYALTY OR REVENUE
8 FREE PURPOSES.  IN NO EVENT SHALL THE END-USER USE THE COMPUTER CODE
9 CONTAINED HEREIN FOR REVENUE-BEARING PURPOSES.  THE END-USER UNDERSTANDS
10 AND AGREES TO THE TERMS HEREIN AND ACCEPTS THE SAME BY USE OF THIS FILE.  
11 COPYRIGHT 1993-1999 PARALLAX SOFTWARE CORPORATION.  ALL RIGHTS RESERVED.
12 */
13
14 #ifndef _GR_H
15 #define _GR_H
16
17 #include "types.h"
18 #include "fix.h"
19
20 #define GR_FADE_LEVELS 34
21 #define GR_ACTUAL_FADE_LEVELS 32
22
23 extern int Gr_scanline_darkening_level;
24
25 typedef struct _grs_point {
26         fix     x,y;
27 } grs_point;
28
29 //these are control characters that have special meaning in the font code
30
31 #define CC_COLOR                        1               //next char is new foreground color
32 #define CC_LSPACING             2               //next char specifies line spacing
33 #define CC_UNDERLINE            3               //next char is underlined
34
35 //now have string versions of these control characters (can concat inside a string)
36
37 #define CC_COLOR_S              "\x1"           //next char is new foreground color
38 #define CC_LSPACING_S   "\x2"           //next char specifies line spacing
39 #define CC_UNDERLINE_S  "\x3"           //next char is underlined
40
41 typedef struct _grs_font {
42         short           ft_w,ft_h;              // Width and height in pixels
43         short           ft_flags;               // Proportional?
44         short           ft_baseline;    //
45         ubyte           ft_minchar,             // The first and last chars defined by
46                                 ft_maxchar;             // This font
47         short           ft_bytewidth;   // Width in unsigned chars
48         ubyte   *       ft_data;                        // Ptr to raw data.
49         ubyte   **      ft_chars;               // Ptrs to data for each char (required for prop font)
50         short   *       ft_widths;              // Array of widths (required for prop font)
51         ubyte *  ft_kerndata;   // Array of kerning triplet data
52 } grs_font;
53
54 #define BM_LINEAR   0
55 #define BM_MODEX    1
56 #define BM_SVGA     2
57 #define BM_RGB15    3   //5 bits each r,g,b stored at 16 bits
58 #define BM_SVGA15   4
59
60 //@@//  Define these modes for Gameplay too, since the game was developed under
61 //@@//  DOS, we will adapt these modes to other systems thru rendering.
62 //@@#define SM_ORIGINAL         -1
63 //@@#define SM_320x200C     0
64 //@@#define SM_320x200U     1
65 //@@#define SM_320x240U     2
66 //@@#define SM_360x200U     3
67 //@@#define SM_360x240U     4
68 //@@#define SM_376x282U     5
69 //@@#define SM_320x400U     6
70 //@@#define SM_320x480U     7
71 //@@#define SM_360x400U     8
72 //@@#define SM_360x480U     9
73 //@@#define SM_360x360U     10
74 //@@#define SM_376x308U     11
75 //@@#define SM_376x564U     12
76 //@@#define SM_640x400V     13
77 //@@#define SM_640x480V     14
78 //@@#define SM_800x600V     15
79 //@@#define SM_1024x768V    16
80 //@@#define SM_640x480V15   17
81 //@@#define SM_800x600V15   18
82
83
84 #define BM_FLAG_TRANSPARENT                     1
85 #define BM_FLAG_SUPER_TRANSPARENT       2
86 #define BM_FLAG_NO_LIGHTING                     4
87 #define BM_FLAG_RLE                                             8                       // A run-length encoded bitmap.
88 #define BM_FLAG_PAGED_OUT                               16                      // This bitmap's data is paged out.
89
90 typedef struct _grs_bitmap {
91         short       bm_x,bm_y;      // Offset from parent's origin
92         short       bm_w,bm_h;      // width,height
93         byte            bm_type;        // 0=Linear, 1=ModeX, 2=SVGA
94         byte                    bm_flags;               // bit 0 on means it has transparency.
95                                                                                 // bit 1 on means it has supertransparency
96                                                                                 // bit 2 on means it doesn't get passed through lighting.
97         short       bm_rowsize;     // unsigned char offset to next row
98         unsigned char *      bm_data;        // ptr to pixel data...
99                                                                 //   Linear = *parent+(rowsize*y+x)
100                                                                 //   ModeX = *parent+(rowsize*y+x/4)
101                                                                 //   SVGA = *parent+(rowsize*y+x)
102         unsigned short bm_selector;
103         ubyte                   avg_color;              //      Average color of all pixels in texture map.
104         byte                    unused;                 //      to 4-byte align.
105 } grs_bitmap;
106
107 typedef struct _grs_canvas {
108         grs_bitmap  cv_bitmap;      // the bitmap for this canvas
109         short       cv_color;       // current color
110         short       cv_drawmode;    // fill,XOR,etc.
111         grs_font *  cv_font;        // the currently selected font
112         short       cv_font_fg_color;   // current font foreground color (-1==Invisible)
113         short       cv_font_bg_color;   // current font background color (-1==Invisible)
114 } grs_canvas;
115
116 typedef struct _grs_screen {     // This is a video screen
117         grs_canvas  sc_canvas;      // Represents the entire screen
118         short       sc_mode;        // Video mode number
119         short       sc_w, sc_h;     // Actual Width and Height
120         fix                     sc_aspect;              //aspect ratio (w/h) for this screen
121 } grs_screen;
122
123
124 //=========================================================================
125 // System functions:
126 // setup and set mode. this creates a grs_screen structure and sets
127 // grd_curscreen to point to it.  grs_curcanv points to this screen's
128 // canvas.  Saves the current VGA state and screen mode.
129                                                   
130 int gr_init(void);
131
132 // This function sets up the main screen.  It should be called whenever
133 // the video mode changes. 
134 int gr_init_screen(int mode, int w, int h, int rowsize, ubyte *data);
135
136
137 // These 4 functions actuall change screen colors.
138
139 extern void gr_pal_fade_out(unsigned char * pal);
140 extern void gr_pal_fade_in(unsigned char * pal);
141 extern void gr_pal_clear(void);
142 extern void gr_pal_setblock( int start, int number, unsigned char * pal );
143 extern void gr_pal_getblock( int start, int number, unsigned char * pal );
144
145
146 extern unsigned char *gr_video_memory;
147                                                                                                 // All graphic modules will define this value.
148
149 //shut down the 2d.  Restore the screen mode.
150 int gr_close(void);
151
152 //=========================================================================
153 // Canvas functions:
154
155 // Makes a new canvas. allocates memory for the canvas and its bitmap,
156 // including the raw pixel buffer.
157
158 grs_canvas *gr_create_canvas(int w, int h);
159
160 // Creates a canvas that is part of another canvas.  this can be used to make
161 // a window on the screen.  the canvas structure is malloc'd; the address of
162 // the raw pixel data is inherited from the parent canvas.
163
164 grs_canvas *gr_create_sub_canvas(grs_canvas *canv,int x,int y,int w, int h);
165
166 // Initialize the specified canvas. the raw pixel data buffer is passed as
167 // a parameter. no memory allocation is performed.
168
169 gr_init_canvas(grs_canvas *canv,unsigned char *pixdata,int pixtype, int w,int h);
170
171 // Initialize the specified sub canvas. no memory allocation is performed.
172
173 gr_init_sub_canvas(grs_canvas *new,grs_canvas *src,int x,int y,int w, int h);
174
175 // Free up the canvas and its pixel data.
176
177 gr_free_canvas(grs_canvas *canv);
178
179 // Free up the canvas. do not free the pixel data, which belongs to the
180 // parent canvas.
181
182 gr_free_sub_canvas(grs_canvas *canv);
183
184 // Clear the current canvas to the specified color
185 gr_clear_canvas(int color);
186
187 //=========================================================================
188 // Bitmap functions:
189
190 // Allocate a bitmap and its pixel data buffer.
191 grs_bitmap *gr_create_bitmap(int w,int h);
192
193 // Allocated a bitmap and makes its data be raw_data that is already somewhere.
194 grs_bitmap *gr_create_bitmap_raw(int w, int h, unsigned char * raw_data );
195
196 // Creates a bitmap which is part of another bitmap
197 grs_bitmap *gr_create_sub_bitmap(grs_bitmap *bm,int x,int y,int w, int h);
198
199 // Free the bitmap and its pixel data
200 gr_free_bitmap(grs_bitmap *bm);
201
202 // Free the bitmap, but not the pixel data buffer
203 gr_free_sub_bitmap(grs_bitmap *bm);
204
205 void gr_bm_pixel( grs_bitmap * bm, int x, int y, unsigned char color );
206 void gr_bm_upixel( grs_bitmap * bm, int x, int y, unsigned char color );
207 void gr_bm_ubitblt( int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
208 void gr_bm_ubitbltm(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
209
210 void gr_update_buffer( void * sbuf1, void * sbuf2, void * dbuf, int size );
211
212 //=========================================================================
213 // Color functions:
214
215 // When this function is called, the guns are set to gr_palette, and
216 // the palette stays the same until gr_close is called
217
218 void gr_use_palette_table(char * filename );
219
220 //=========================================================================
221 // Drawing functions:
222
223 // For solid, XOR, or other fill modes.
224 gr_set_drawmode(int mode);
225
226 // Sets the color in the current canvas.  should be a macro
227 // Use: gr_setcolor(int color);
228 void gr_setcolor(int color);
229
230 // Draw a polygon into the current canvas in the current color and drawmode.
231 // verts points to an ordered list of x,y pairs.  the polygon should be
232 // convex; a concave polygon will be handled in some reasonable manner,
233 // but not necessarily shaded as a concave polygon. It shouldn't hang.
234 // probably good solution is to shade from minx to maxx on each scan line.
235 // int should really be fix
236 gr_poly(int nverts,int *verts);
237 gr_upoly(int nverts,int *verts);
238
239
240 // Draws a point into the current canvas in the current color and drawmode.
241 gr_pixel(int x,int y);
242 gr_upixel(int x,int y);
243
244 // Gets a pixel;
245 unsigned char gr_gpixel( grs_bitmap * bitmap, int x, int y );
246 unsigned char gr_ugpixel( grs_bitmap * bitmap, int x, int y );
247
248 // Draws a line into the current canvas in the current color and drawmode.
249 int gr_line(fix x0,fix y0,fix x1,fix y1);
250 int gr_uline(fix x0,fix y0,fix x1,fix y1);
251
252 // Draws an anti-aliased line into the current canvas in the current color and drawmode.
253 int gr_aaline(fix x0,fix y0,fix x1,fix y1);
254 int gr_uaaline(fix x0,fix y0,fix x1,fix y1);
255
256 // Draw the bitmap into the current canvas at the specified location.
257 gr_bitmap(int x,int y,grs_bitmap *bm);
258 gr_ubitmap(int x,int y,grs_bitmap *bm);
259 // bitmap function with transparency
260 gr_bitmapm( int x, int y, grs_bitmap *bm );
261 gr_ubitmapm( int x, int y, grs_bitmap *bm );
262
263 // Draw a rectangle into the current canvas.
264 gr_rect(int left,int top,int right,int bot);
265 gr_urect(int left,int top,int right,int bot);
266
267 // Draw a filled circle
268 int gr_disk(fix x,fix y,fix r);
269 int gr_udisk(fix x,fix y,fix r);
270
271 // Draw an outline circle
272 gr_circle(fix x,fix y,fix r);
273 gr_ucircle(fix x,fix y,fix r);
274
275 // Draw an unfilled rectangle into the current canvas
276 gr_box(int left,int top,int right,int bot);
277 gr_ubox(int left,int top,int right,int bot);
278
279 void gr_scanline( int x1, int x2, int y );
280 void gr_uscanline( int x1, int x2, int y );
281
282
283 // Reads in a font file... current font set to this one.
284 grs_font * gr_init_font( char * fontfile );
285 void gr_close_font( grs_font * font );
286
287 //remap a font, re-reading its data & palette 
288 void gr_remap_font( grs_font *font, char * fontname );
289
290 //remap (by re-reading) all the color fonts
291 void gr_remap_color_fonts();
292
293 // Writes a string using current font. Returns the next column after last char.
294 void gr_set_fontcolor( int fg, int bg );
295 void gr_set_curfont( grs_font * new );
296 int gr_string(int x, int y, char *s );
297 int gr_ustring(int x, int y, char *s );
298 int gr_printf( int x, int y, char * format, ... );
299 int gr_uprintf( int x, int y, char * format, ... );
300 void gr_get_string_size(char *s, int *string_width, int *string_height, int *average_width );
301
302
303 //      From roller.c
304 void rotate_bitmap(grs_bitmap *bp, grs_point *vertbuf, int light_value);
305
306 // From scale.c
307 void scale_bitmap(grs_bitmap *bp, grs_point *vertbuf, int orientation );
308
309 //===========================================================================
310 // Global variables
311 extern grs_canvas *grd_curcanv;             //active canvas
312 extern grs_screen *grd_curscreen;           //active screen
313 extern unsigned char Test_bitmap_data[64*64];
314
315 extern unsigned int FixDivide( unsigned int x, unsigned int y );
316
317 extern void gr_show_canvas( grs_canvas *canv );
318 extern void gr_set_current_canvas( grs_canvas *canv );
319
320 //flags for fonts
321 #define FT_COLOR                        1
322 #define FT_PROPORTIONAL 2
323 #define FT_KERNED                       4
324
325 extern void gr_vesa_update( grs_bitmap * source1, grs_bitmap * dest, grs_bitmap * source2 );
326
327 // Special effects
328 extern void gr_snow_out(int num_dots);
329
330 extern void test_rotate_bitmap(void);
331 extern void rotate_bitmap(grs_bitmap *bp, grs_point *vertbuf, int light_value);
332
333 extern ubyte gr_palette[256*3];
334 extern ubyte gr_fade_table[];
335 extern ubyte gr_inverse_table[32*32*32];
336
337 extern ushort gr_palette_selector;
338 extern ushort gr_inverse_table_selector;
339 extern ushort gr_fade_table_selector;
340
341 // Remaps a bitmap into the current palette. If transparent_color is between 0 and 255
342 // then all occurances of that color are mapped to whatever color the 2d uses for 
343 // transparency. This is normally used right after a call to iff_read_bitmap like
344 // this:
345 //              iff_error = iff_read_bitmap(filename,new,BM_LINEAR,newpal);
346 //              if (iff_error != IFF_NO_ERROR) Error("Can't load IFF file <%s>, error=%d",filename,iff_error);
347 //              if ( iff_has_transparency )
348 //                      gr_remap_bitmap( new, newpal, iff_transparent_color );
349 //              else
350 //                      gr_remap_bitmap( new, newpal, -1 );
351 extern void gr_remap_bitmap( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color );
352
353 // Same as above, but searches using gr_find_closest_color which uses 18-bit accurracy
354 // instaed of 15bit when translating colors.
355 extern void gr_remap_bitmap_good( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color );
356
357 extern void gr_palette_step_up( int r, int g, int b );
358
359 extern void gr_bitmap_check_transparency( grs_bitmap * bmp );
360
361 // Allocates a selector that has a base address at 'address' and length 'size'.
362 // Returns 0 if successful... BE SURE TO CHECK the return value since there
363 // is a limited number of selectors available!!!
364 extern int get_selector( void * address, int size, unsigned int * selector );
365
366 // Assigns a selector to a bitmap. Returns 0 if successful.  BE SURE TO CHECK
367 // this return value since there is a limited number of selectors!!!!!!!
368 extern int gr_bitmap_assign_selector( grs_bitmap * bmp );
369
370 //#define GR_GETCOLOR(r,g,b) (gr_inverse_table[( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )])
371 //#define gr_getcolor(r,g,b) (gr_inverse_table[( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )])
372 //#define BM_XRGB(r,g,b) (gr_inverse_table[( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )])
373
374 #define BM_RGB(r,g,b) ( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )
375 #define BM_XRGB(r,g,b) gr_find_closest_color( (r)*2,(g)*2,(b)*2 )
376 #define GR_GETCOLOR(r,g,b) gr_find_closest_color( (r)*2,(g)*2,(b)*2 )
377 #define gr_getcolor(r,g,b) gr_find_closest_color( (r)*2,(g)*2,(b)*2 )
378
379 // Given: r,g,b, each in range of 0-63, return the color index that
380 // best matches the input.
381 int gr_find_closest_color( int r, int g, int b );
382
383 extern void gr_merge_textures( ubyte * lower, ubyte * upper, ubyte * dest );
384 extern void gr_merge_textures_1( ubyte * lower, ubyte * upper, ubyte * dest );
385 extern void gr_merge_textures_2( ubyte * lower, ubyte * upper, ubyte * dest );
386 extern void gr_merge_textures_3( ubyte * lower, ubyte * upper, ubyte * dest );
387
388 #endif
389