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.
21 #define SWAP_0_255 1 // swap black and white
22 #define TRANSPARENCY_COLOR 0 // palette entry of transparency color -- 0 on the mac
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
28 #define GR_FADE_LEVELS 34
29 #define GR_ACTUAL_FADE_LEVELS 32
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)
37 extern int Gr_scanline_darkening_level;
39 typedef struct _grs_point {
43 //these are control characters that have special meaning in the font code
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
49 //now have string versions of these control characters (can concat inside a string)
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
55 typedef struct _old_grs_font {
56 short ft_w,ft_h; // Width and height in pixels
57 short ft_flags; // Proportional?
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;
71 #define BM_RGB15 3 //5 bits each r,g,b stored at 16 bits
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)
85 #define SM_ORIGINAL -1
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
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)
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.
131 struct _ogl_texture *gltexture;
132 struct _grs_bitmap *bm_parent;
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
151 old_grs_font * oldfont;
152 grs_bitmap *ft_bitmaps;
153 grs_bitmap ft_parent_bitmap;
157 typedef struct _grs_canvas {
158 grs_bitmap cv_bitmap; // the bitmap for this canvas
159 short cv_color; // current color
160 short cv_drawmode; // fill,XOR,etc.
161 grs_font * cv_font; // the currently selected font
162 short cv_font_fg_color; // current font foreground color (-1==Invisible)
163 short cv_font_bg_color; // current font background color (-1==Invisible)
167 #define cv_w cv_bitmap.bm_w
168 #define cv_h cv_bitmap.bm_h
170 typedef struct _grs_screen { // This is a video screen
171 grs_canvas sc_canvas; // Represents the entire screen
172 int sc_mode; // Video mode number
173 short sc_w, sc_h; // Actual Width and Height
174 fix sc_aspect; //aspect ratio (w/h) for this screen
178 //=========================================================================
180 // setup and set mode. this creates a grs_screen structure and sets
181 // grd_curscreen to point to it. grs_curcanv points to this screen's
182 // canvas. Saves the current VGA state and screen mode.
186 // This function sets up the main screen. It should be called whenever
187 // the video mode changes.
188 int gr_init_screen(int mode, int w, int h, int x, int y, int rowsize, ubyte *data);
190 int gr_check_mode(u_int32_t mode);
191 int gr_set_mode(u_int32_t mode);
194 // These 4 functions actuall change screen colors.
196 extern void gr_pal_fade_out(unsigned char * pal);
197 extern void gr_pal_fade_in(unsigned char * pal);
198 extern void gr_pal_clear(void);
199 extern void gr_pal_setblock( int start, int number, unsigned char * pal );
200 extern void gr_pal_getblock( int start, int number, unsigned char * pal );
203 extern unsigned char *gr_video_memory;
204 // All graphic modules will define this value.
206 //shut down the 2d. Restore the screen mode.
209 //=========================================================================
212 // Makes a new canvas. allocates memory for the canvas and its bitmap,
213 // including the raw pixel buffer.
215 grs_canvas *gr_create_canvas(int w, int h);
216 #if defined(POLY_ACC)
217 grs_canvas *gr_create_canvas2(int w, int h, int type);
220 // Creates a canvas that is part of another canvas. this can be used to make
221 // a window on the screen. the canvas structure is malloc'd; the address of
222 // the raw pixel data is inherited from the parent canvas.
224 grs_canvas *gr_create_sub_canvas(grs_canvas *canv,int x,int y,int w, int h);
226 // Initialize the specified canvas. the raw pixel data buffer is passed as
227 // a parameter. no memory allocation is performed.
229 void gr_init_canvas(grs_canvas *canv,unsigned char *pixdata,int pixtype, int w,int h);
231 // Initialize the specified sub canvas. no memory allocation is performed.
233 void gr_init_sub_canvas(grs_canvas *new,grs_canvas *src,int x,int y,int w, int h);
235 // Free up the canvas and its pixel data.
237 void gr_free_canvas(grs_canvas *canv);
239 // Free up the canvas. do not free the pixel data, which belongs to the
242 void gr_free_sub_canvas(grs_canvas *canv);
244 // Clear the current canvas to the specified color
245 void gr_clear_canvas(int color);
247 //=========================================================================
250 // Allocate a bitmap and its pixel data buffer.
251 grs_bitmap *gr_create_bitmap(int w,int h);
253 // Allocated a bitmap and makes its data be raw_data that is already somewhere.
254 grs_bitmap *gr_create_bitmap_raw(int w, int h, unsigned char * raw_data );
256 #if defined(POLY_ACC)
257 // Allocates a bitmap of a specific type. data is either NULL or raw data.
258 grs_bitmap *gr_create_bitmap2(int w, int h, int type, void *data );
261 // Creates a bitmap which is part of another bitmap
262 grs_bitmap *gr_create_sub_bitmap(grs_bitmap *bm,int x,int y,int w, int h);
264 // Free the bitmap and its pixel data
265 void gr_free_bitmap(grs_bitmap *bm);
267 // Free the bitmap, but not the pixel data buffer
268 void gr_free_sub_bitmap(grs_bitmap *bm);
270 void gr_bm_pixel( grs_bitmap * bm, int x, int y, unsigned char color );
271 void gr_bm_upixel( grs_bitmap * bm, int x, int y, unsigned char color );
272 void gr_bm_ubitblt( int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
273 void gr_bm_ubitbltm(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap * src, grs_bitmap * dest);
276 void gr_bm_ubitblt_double(int w, int h, int dx, int dy, int sx, int sy, grs_bitmap *src, grs_bitmap *dest);
277 void gr_linear_movsd_double(ubyte *src, ubyte *dest, int num_pixels);
280 void gr_update_buffer( void * sbuf1, void * sbuf2, void * dbuf, int size );
282 //=========================================================================
285 // When this function is called, the guns are set to gr_palette, and
286 // the palette stays the same until gr_close is called
288 void gr_use_palette_table(char * filename );
289 void gr_copy_palette(ubyte *gr_palette, ubyte *pal, int size);
291 //=========================================================================
292 // Drawing functions:
294 // For solid, XOR, or other fill modes.
295 int gr_set_drawmode(int mode);
297 // Sets the color in the current canvas. should be a macro
298 // Use: gr_setcolor(int color);
299 void gr_setcolor(int color);
301 // Draw a polygon into the current canvas in the current color and drawmode.
302 // verts points to an ordered list of x,y pairs. the polygon should be
303 // convex; a concave polygon will be handled in some reasonable manner,
304 // but not necessarily shaded as a concave polygon. It shouldn't hang.
305 // probably good solution is to shade from minx to maxx on each scan line.
306 // int should really be fix
307 int gr_poly(int nverts,int *verts);
308 int gr_upoly(int nverts,int *verts);
311 // Draws a point into the current canvas in the current color and drawmode.
312 void gr_pixel(int x,int y);
313 void gr_upixel(int x,int y);
316 unsigned char gr_gpixel( grs_bitmap * bitmap, int x, int y );
317 unsigned char gr_ugpixel( grs_bitmap * bitmap, int x, int y );
319 // Draws a line into the current canvas in the current color and drawmode.
320 int gr_line(fix x0,fix y0,fix x1,fix y1);
321 int gr_uline(fix x0,fix y0,fix x1,fix y1);
323 // Draws an anti-aliased line into the current canvas in the current color and drawmode.
324 int gr_aaline(fix x0,fix y0,fix x1,fix y1);
325 int gr_uaaline(fix x0,fix y0,fix x1,fix y1);
327 // Draw the bitmap into the current canvas at the specified location.
328 void gr_bitmap(int x,int y,grs_bitmap *bm);
329 void gr_ubitmap(int x,int y,grs_bitmap *bm);
330 // bitmap function with transparency
331 void gr_bitmapm( int x, int y, grs_bitmap *bm );
332 void gr_ubitmapm( int x, int y, grs_bitmap *bm );
334 // Draw a rectangle into the current canvas.
335 void gr_rect(int left,int top,int right,int bot);
336 void gr_urect(int left,int top,int right,int bot);
338 // Draw a filled circle
339 int gr_disk(fix x,fix y,fix r);
340 int gr_udisk(fix x,fix y,fix r);
342 // Draw an outline circle
343 int gr_circle(fix x,fix y,fix r);
344 int gr_ucircle(fix x,fix y,fix r);
346 // Draw an unfilled rectangle into the current canvas
347 void gr_box(int left,int top,int right,int bot);
348 void gr_ubox(int left,int top,int right,int bot);
350 void gr_scanline( int x1, int x2, int y );
351 void gr_uscanline( int x1, int x2, int y );
354 // Reads in a font file... current font set to this one.
355 grs_font * gr_init_font( char * fontfile );
356 void gr_close_font( grs_font * font );
358 //remap a font, re-reading its data & palette
359 void gr_remap_font( grs_font *font, char * fontname );
361 //remap (by re-reading) all the color fonts
362 void gr_remap_color_fonts();
364 // Writes a string using current font. Returns the next column after last char.
365 void gr_set_fontcolor( int fg, int bg );
366 void gr_set_curfont( grs_font * new );
367 int gr_string(int x, int y, char *s );
368 int gr_ustring(int x, int y, char *s );
369 int gr_printf( int x, int y, char * format, ... );
370 int gr_uprintf( int x, int y, char * format, ... );
371 void gr_get_string_size(char *s, int *string_width, int *string_height, int *average_width );
375 void rotate_bitmap(grs_bitmap *bp, grs_point *vertbuf, int light_value);
378 void scale_bitmap(grs_bitmap *bp, grs_point *vertbuf, int orientation );
380 //===========================================================================
382 extern grs_canvas *grd_curcanv; //active canvas
383 extern grs_screen *grd_curscreen; //active screen
384 extern unsigned char Test_bitmap_data[64*64];
386 //shortcut to look at current font
387 #define grd_curfont grd_curcanv->cv_font
389 extern unsigned int FixDivide( unsigned int x, unsigned int y );
391 extern void gr_show_canvas( grs_canvas *canv );
392 extern void gr_set_current_canvas( grs_canvas *canv );
396 #define FT_PROPORTIONAL 2
399 extern void gr_vesa_update( grs_bitmap * source1, grs_bitmap * dest, grs_bitmap * source2 );
402 extern void gr_snow_out(int num_dots);
404 extern void test_rotate_bitmap(void);
405 extern void rotate_bitmap(grs_bitmap *bp, grs_point *vertbuf, int light_value);
407 extern ubyte gr_palette[256*3];
408 extern ubyte gr_fade_table[256*GR_FADE_LEVELS];
409 extern ubyte gr_inverse_table[32*32*32];
411 extern ushort gr_palette_selector;
412 extern ushort gr_inverse_table_selector;
413 extern ushort gr_fade_table_selector;
415 // Remaps a bitmap into the current palette. If transparent_color is between 0 and 255
416 // then all occurances of that color are mapped to whatever color the 2d uses for
417 // transparency. This is normally used right after a call to iff_read_bitmap like
419 // iff_error = iff_read_bitmap(filename,new,BM_LINEAR,newpal);
420 // if (iff_error != IFF_NO_ERROR) Error("Can't load IFF file <%s>, error=%d",filename,iff_error);
421 // if ( iff_has_transparency )
422 // gr_remap_bitmap( new, newpal, iff_transparent_color );
424 // gr_remap_bitmap( new, newpal, -1 );
425 extern void gr_remap_bitmap( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color );
427 // Same as above, but searches using gr_find_closest_color which uses 18-bit accurracy
428 // instaed of 15bit when translating colors.
429 extern void gr_remap_bitmap_good( grs_bitmap * bmp, ubyte * palette, int transparent_color, int super_transparent_color );
431 extern void gr_palette_step_up( int r, int g, int b );
433 extern void gr_bitmap_check_transparency( grs_bitmap * bmp );
435 // Allocates a selector that has a base address at 'address' and length 'size'.
436 // Returns 0 if successful... BE SURE TO CHECK the return value since there
437 // is a limited number of selectors available!!!
438 extern int get_selector( void * address, int size, unsigned int * selector );
440 // Assigns a selector to a bitmap. Returns 0 if successful. BE SURE TO CHECK
441 // this return value since there is a limited number of selectors!!!!!!!
442 extern int gr_bitmap_assign_selector( grs_bitmap * bmp );
444 //#define GR_GETCOLOR(r,g,b) (gr_inverse_table[( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )])
445 //#define gr_getcolor(r,g,b) (gr_inverse_table[( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )])
446 //#define BM_XRGB(r,g,b) (gr_inverse_table[( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )])
448 #define BM_RGB(r,g,b) ( (((r)&31)<<10) | (((g)&31)<<5) | ((b)&31) )
449 #define BM_XRGB(r,g,b) gr_find_closest_color( (r)*2,(g)*2,(b)*2 )
450 #define GR_GETCOLOR(r,g,b) gr_find_closest_color( (r)*2,(g)*2,(b)*2 )
451 #define gr_getcolor(r,g,b) gr_find_closest_color( (r)*2,(g)*2,(b)*2 )
453 // Given: r,g,b, each in range of 0-63, return the color index that
454 // best matches the input.
455 int gr_find_closest_color( int r, int g, int b );
456 int gr_find_closest_color_15bpp( int rgb );
458 extern void gr_merge_textures( ubyte * lower, ubyte * upper, ubyte * dest );
459 extern void gr_merge_textures_1( ubyte * lower, ubyte * upper, ubyte * dest );
460 extern void gr_merge_textures_2( ubyte * lower, ubyte * upper, ubyte * dest );
461 extern void gr_merge_textures_3( ubyte * lower, ubyte * upper, ubyte * dest );
463 extern void gr_update(void);
466 * currently SDL and OGL are the only things that supports toggling
467 * fullscreen. otherwise add other checks to the #if -MPM
469 #if (defined(SDL_VIDEO) || defined(OGL))
470 #define GR_SUPPORTS_FULLSCREEN_TOGGLE
473 * must return 0 if windowed, 1 if fullscreen
475 int gr_check_fullscreen(void);
478 * returns state after toggling (ie, same as if you had called
479 * check_fullscreen immediatly after)
481 int gr_toggle_fullscreen(void);