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