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